首先,我在 components
- parameters
里定义了一个offset
参数:
components:
parameters:
offset:
name: offset
in: query
description: 跳过的数据数
schema:
type: integer
format: int64
minimum: 1
然后,我在paths
的parameters
字段里引用:
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
对象至少应该包含content
和schema
中的一个字段,但明明已经定义了。
翻了下官方文档的示例:
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
。
GitHub issue