определить общие параметры для аннотаций openapi / swagger - PullRequest
0 голосов
/ 11 декабря 2018

На https://swagger.io/docs/specification/describing-parameters/ (OAS3) есть пример для общих параметров, на которые может ссылаться $ ref в путях и операциях:

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

Как бы я объявил аннотации Swagger для создания этоговывод, особенно если параметры имеют примитивный тип?

Я пытался

@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;
    }
}

, но я получил только

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

У вас есть идеи, какие аннотации v3 добавитьк ресурсу JAX-RS 2.1?Моя цель - определить эти общие параметры один раз и ссылаться на них во всех ресурсах моего приложения.

...