Skip to content

Support OpenAPI @io.swagger.v3.oas.annotations.Parameter on method parameters #3461

@agentgt

Description

@agentgt

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:

https://github.com/jooby-project/jooby/blob/532cc00de921ce8ecb107aeadf83b38281de78af/modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/OpenAPIParser.java#L489C1-L490C1

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions