how to pass multi value query params in swagger

前端 未结 2 843
时光说笑
时光说笑 2021-01-17 14:24

I have following service in swagger.yml. The service is written so that page_id can be passed multiple times. e.g /pages?page_id[]=123&page_id[]=542

2条回答
  •  醉梦人生
    2021-01-17 14:59

    You are almost there. Name the parameter page_id[], make it type: array and use 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
    

    Note that the requests will be sent with the [ and ] characters percent-encoded as %5B and %5D, because they are reserved characters according to RFC 3986.

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

提交回复
热议问题