2

On https://swagger.io/docs/specification/describing-parameters/ (OAS3) there is an example for common parameters which can be refered by $ref in paths and operations:

components:
  parameters:
    offsetParam:  # <-- Arbitrary name for the definition that will be used to refer to it.
                  # Not necessarily the same as the parameter name.
      in: query
      name: offset
      required: false
      schema:
        type: integer
        minimum: 0
      description: The number of items to skip before starting to collect the result set.
    limitParam:
      in: query
      name: limit
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 50
        default: 20
      description: The numbers of items to return.
paths:
  /users:
    get:
      summary: Gets a list of users.
      parameters:
        - $ref: '#/components/parameters/offsetParam'
        - $ref: '#/components/parameters/limitParam'
      responses:
        '200':
          description: OK
  /teams:
    get:
      summary: Gets a list of teams.
      parameters:
        - $ref: '#/components/parameters/offsetParam'
        - $ref: '#/components/parameters/limitParam'
      responses:
        '200':
          description: OK

How would I declare Swagger Annotations to produce this output, especially if the parameters are primitive type?

I tried

@Schema(type = "int")
@OpenAPIDefinition(info = @Info(description = "descr"))
public class OffsetParam {
    public static final String DESCRIPTION =
            "The number of items to skip before starting to collect the result set.";

    @Parameter(description = "desc1")
    public static OffsetParam valueOf(String value) {
        return null;
    }
}

but I only got

 "components" : {
    "schemas" : {
      "OffsetParam" : {
        "type" : "object"
      },...

Do you have any idea which v3 annotations to add to a JAX-RS 2.1 resource? My goal is to define those common parameters once and refer to them in all resources across my application.

Matthias Wiedemann
  • 1,313
  • 12
  • 22
  • Have the same issue. I even added a ref to @Parameter, for example @Parameter(ref="OffsetParam") And then manually added the following to the generated spec: "components" : { "parameters": { "OffsetParam": { "name": "blah" } }, Which worked. So my conclusion that the spec allows it, but the annotations are limited – Stephen Mar 18 '20 at 11:50
  • Did you ever figure this out? – ccleve Dec 10 '20 at 16:09

0 Answers0