Bae*_*row 6 swagger swagger-2.0 openapi
我正在编写一个 OpenAPI (Swagger) 定义,其中查询参数可以没有或 N 个值,如下所示:
/path?sort=field1,field2
Run Code Online (Sandbox Code Playgroud)
如何在 OpenAPI YAML 中编写它?
我尝试了以下方法,但没有产生预期的结果:
/path?sort=field1,field2
Run Code Online (Sandbox Code Playgroud)
Hel*_*len 10
包含逗号分隔值列表的查询参数定义为数组。如果这些值是预定义的,那么它是一个enum 数组。
默认情况下,一个数组可能有任意数量的项目,这符合您的“无或更多”要求。如果需要,您可以使用minItems和限制项目数量,也可以maxItems选择执行uniqueItems: true。
参数定义如下所示。collectionFormat: csv表示值以逗号分隔,但这是默认格式,因此可以省略。
parameters:
- name: sort
in: query
type: array # <-----
items:
type: string
enum: [field1, field2, field3]
collectionFormat: csv # <-----
required: false
description: Sort the results by attributes. (See http://jsonapi.org/format/1.1/#fetching-sorting)
Run Code Online (Sandbox Code Playgroud)
collectionFormat: csv来自 OpenAPI 2.0 已被替换为style: form+ explode: false。style: form是查询参数的默认样式,因此可以省略。
parameters:
- name: sort
in: query
schema:
type: array # <-----
items:
type: string
enum: [field1, field2, field3]
required: false
description: Sort the results by attributes. (See http://jsonapi.org/format/1.1/#fetching-sorting)
explode: false # <-----
Run Code Online (Sandbox Code Playgroud)
我认为没有必要allowEmptyValue,因为在这种情况下,空数组实际上是一个空值。此外,allowEmptyValue是不建议使用,因为OpenAPI的3.0.2“因为它会在将来的版本中删除。”
| 归档时间: |
|
| 查看次数: |
7202 次 |
| 最近记录: |