-
-
Notifications
You must be signed in to change notification settings - Fork 201
Description
It appears the only way to get @Parameter working with OpenAPI is to use the @Operation (and I think @Parameters) on the method and not the parameter.
@io.swagger.v3.oas.annotations.Operation(parameters = { @Parameter(name = "orgId", required = true) })
public Blah getBlah(@QueryParam UUID orgId, ...)However it is documented that Swagger does support the easier annotate parameter directly which is less error prone as one does not have to write the parameter name twice:
public Blah getBlah(@io.swagger.v3.oas.annotations.Parameter(required = true) @QueryParam UUID orgId, ...)I have known about this for awhile but was too lazy to file a feature request for it. It also begs the question how does one merge if parameter is specified in multiple places but I assume the annotated parameter itself takes precedence.
I know its somewhere around here to add it: https://github.com/jooby-project/jooby/blob/3.x/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/OpenAPIParser.java#L212
By the way I have noticed we do a lot of annotation parsing the hard way. An easier way for future notice is to use a "prism" generator. An example project that generates prisms is: https://github.com/avaje/avaje-prisms
In fact I convinced the guys from Avaje ( @SentryMan ) that this is the way and why they even made their own version.
For example the @Parameter can have a prism generated so that you can do
var parameter = ParameterPrism.getInstance(element);
parameter.required() // gets the @Parameter(required=...)Instead of:
The former is type safe and less error prone.
Basically it turns all the annotations into an object graph you would use just like if you used reflection (hence prism).
You can also get module path issues as you accessing the swagger annotations directly instead of by String. The prism generators fix that issue.