为openapi / swagger注释定义通用参数

时间:2018-12-11 15:21:37

标签: annotations jax-rs swagger openapi

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资源? 我的目标是一次定义这些通用参数,并在我的应用程序的所有资源中引用它们。

0 个答案:

没有答案