我在 swagger.yml 中有以下服务。编写服务以便可以多次传递 page_id。例如 /pages?page_id[]=123&page_id[]=542
我检查了这个链接 https://swagger.io/specification/但无法理解如何更新 yml 以便我可以多次传递 id。
我知道我必须设置 collectionFormat
但不知道如何设置。
我尝试像下面那样更新它,但没有成功 https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md .
它生成类似“http://localhost:0000/pages?page_id=123%2C%20542”的 url `
'/pages':
get:
tags:
-
summary: get the list of pages
operationId: getPages
produces:
- application/json
parameters:
- name: page_id
in: query
description: some description
required: false
type: string
collectionFormat: multi
- name: page_detail
in: query
description: some description
required: false
type: string
responses:
'200':
description: OK
'401':
description: Authentication Failed
'404':
description: Not Found
'503':
description: Service Not Available
最佳答案
你快到了。将参数命名为 page_id[]
,使其成为 type: array
并使用 collectionFormat: multi
:
parameters:
- name: page_id[]
in: query
description: some description
required: false
type: array
items:
type: string # or type: integer or whatever the type is
collectionFormat: multi
请注意,请求将与 [
和 ]
字符一起发送,百分比编码为 %5B
和 %5D
,因为根据 RFC 3986 它们是保留字符。
http://example.com/pages?page_id%5B%5D=123&page_id%5B%5D=456
关于ruby - 如何 Swagger 传递多值查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47420755/