如何在招摇中传递多值查询参数

mik*_*ike 5 ruby swagger

我在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)

Hel*_*len 7

你快到了 命名参数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)

您必须将参数定义为数组。

  • 哪些文档?目前尚不清楚您指的是哪个版本。请提供链接。 (5认同)