我在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。
它生成的URL,如“ HTTP://本地主机:0000 /页PAGE_ID = 123%2C%20542 `
'/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
Run Code Online (Sandbox Code Playgroud)
你快到了 命名参数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
Run Code Online (Sandbox Code Playgroud)
请注意,请求将以[和]字符百分比编码为%5Band发送%5D,因为它们是根据RFC 3986保留的字符。
http://example.com/pages?page_id%5B%5D=123&page_id%5B%5D=456
Run Code Online (Sandbox Code Playgroud)
小智 5
来自文档:
parameters:
- name: id
in: path
description: ID of pet to use
required: true
schema:
type: array
style: simple
items:
type: string
Run Code Online (Sandbox Code Playgroud)
您必须将参数定义为数组。
| 归档时间: |
|
| 查看次数: |
4046 次 |
| 最近记录: |