Swagger Editor parameters components 引用报错?

首先,我在 components - parameters里定义了一个offset参数:

components: 
  parameters: 
    offset:
      name: offset
      in: query
      description: 跳过的数据数
      schema: 
        type: integer
        format: int64
        minimum: 1

然后,我在pathsparameters字段里引用:

paths:
  /todos:
    get: 
      tags: 
        - todos
      summary: 查询
      parameters: 
        - $ref: '#/components/parameters/offset'
      responses: 

swagger editor报错了:

Parameter Object must contain one the following fields: content, schema apilint(5150001)
提示paramter对象至少应该包含contentschema中的一个字段,但明明已经定义了。

image.png


翻了下官方文档的示例:

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

语法没问题呀,为什么报错呢?


2023-02-10

确认是BUG

image.png

GitHub issue
阅读 1.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进