ruby - 如何 Swagger 传递多值查询参数

标签 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 .

它生成类似“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/

相关文章:

ruby-on-rails - 删除浅嵌套 Comment 类返回错误 "Couldn' t 查找没有 ID 的 Comment”(Rails)

Ruby Git Diff 行信息解析器

rest - Swagger 生成的 Spring Controller 在 POST 的主体参数中接收 NULL

c# - ASP.Net MVC - Swashbuckle 无法识别任何 Controller

php - 如何使用全局二级索引创建表 dynamodb

ruby-on-rails - 命名空间 Controller 重定向 url

ruby - Watir 和 Cucumber 无法在 win xp 上运行

ruby - 检查一个散列是否包含另一个散列

Swagger 继承和组合

java - swagger中spring fox health路由显示多个HTTP方法