Swagger UI not sending array correctly

蓝咒 提交于 2019-12-29 09:21:57

问题


I am trying to send multiple values (an array) (refer to on line 93 in spec ->... name: recipients[] ...)

The problem I am facing is the Swagger-ui call the endpoints as below:

Actual

recipients[]=value1%2Cvalue2

Expected

recipients[]=value1&recipients[]=value2

The %2C means , (comma).

Below are the required details swagger-ui version 2.1.1 Below is the link for content of the swagger spec file reproducing the issue: http://pastebin.com/V3ZuCjVz


回答1:


It looks like the way to specify this is to add collectionFormat: multi

- name: recipients[]
  in: formData
  description: Email addresses for recipients (multiple values allowed).
  required: true
  type: array
  collectionFormat: multi
  items:
      type: string

Possible values from http://swagger.io/specification/ are:

  • csv - comma separated values foo,bar.
  • ssv - space separated values foo bar.
  • tsv - tab separated values foo\tbar.
  • pipes - pipe separated values foo|bar.
  • multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz. This is valid only for parameters in "query" or "formData".


来源:https://stackoverflow.com/questions/36329771/swagger-ui-not-sending-array-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!