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

时间:2017-11-21 19:02:25

标签: ruby swagger

我在swagger.yml中有以下服务。编写服务以便可以多次传递page_id。例如collectionFormat

我查看了此链接https://swagger.io/specification/,但无法理解如何更新yml,以便我可以多次传递ID。

我看到我必须设置'/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,但不知道如何。

我尝试像下面一样更新它,但没有运气https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

它生成的网址类似于' http://localhost:0000/pages?page_id=123%2C%20542`

$('#alerts-display, #object-display').on('click', ['.item-data-summary', '.item-marker'], function(e) { e.preventDefault(); var id; id = setTimeout(() => { // code to run here return false; }, 150); timeoutIDForDoubleClick.push(id); }); $('.panel-items-set-marker-view').on('dblclick', ['.summary', '.marker'], function(e) { for (let i = 0; i < timeoutIDForDoubleClick.length; i++) { clearTimeout(timeoutIDForDoubleClick[i]); } // code to run on double click e.preventDefault(); });

2 个答案:

答案 0 :(得分:4)

你快到了。将参数命名为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一起发送,因为它们是根据{{3}保留的字符}}

http://example.com/pages?page_id%5B%5D=123&page_id%5B%5D=456

答案 1 :(得分:0)

来自文档:

parameters:
- name: id
  in: path
  description: ID of pet to use
  required: true
  schema:
    type: array
    style: simple
    items:
      type: string

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