I have, say, a class Person
which, depending on the endpoint, would have its firstName
either required or not. Is there a way of doing this with Swagger OpenAPI documentation tags in Java?
I'm imagining it could look a bit like this if it were/is possible:
public class Person {
@Path("/endpoint1", required = true)
@Path("/endpoint2", required = false)
private String firstName;
}
You'll need two classes - one where the firstName
property is required, and another one where it's optional. To reduce code duplication, you can define a base class that contains all properties except for firstName
and inherit the other two Person classes from this base class.