swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.54k stars 8.96k forks source link

Swagger Not sending array correctly #2067

Closed itabrezshaikh closed 8 years ago

itabrezshaikh commented 8 years ago

Hi,

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).

Please help/guide, its urgent.

Thanks, Tabby

Below are the required details:

pepipost.dev.v4.yaml.txt

webron commented 8 years ago

You need to set the collectionFormat.

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

I tried it but still it does not work. The ui still uses %2c (, comma) and not repeat the params. Below are the details:

* POST call made by swagger-ui * curl -X POST --header 'Content-Type: application/x-www-form-urlencoded' --header 'Accept: application/json' -d 'api_key=2b34032c39ea424f0aaf70ed060af428&from=test%40m3m.in&subject=test&content=test&footer=true&clicktrack=true&opentrack=true&recipients=itabrezshaikh%40gmail.com%2Ctazz.hunk%40gmail.com' 'http://b4f51651.ngrok.io/v1/emails.json'

Here is the new spec after change: http://pastebin.com/t47xjFQw

itabrezshaikh commented 8 years ago

Hi,

Any help will be appreciated...thanks.

fehguy commented 8 years ago

@itabrezshaikh I've opened a ticket in the relevant repo, will try to get to this shortly

itabrezshaikh commented 8 years ago

Thank you @fehguy and @webron ..I will be waiting ..thanks a again :)

dkottow commented 8 years ago

This is related to this issue I am having with TSV values. I believe the option multi is simply not implemented, have a look at the source code on lines 919 - 927 of operation.js. It also looks consistent with the behavior your seeing where it defaults to CSV.

Greetings Daniel

can-can commented 8 years ago

Is this problem fixed? I saw @fehguy fix it in swagger-js, but I don't know how to make swagger-ui work correclty

Somebi commented 8 years ago

Ugh still not working... It seems project is dead. Last release was in January 7.

fehguy commented 8 years ago

Please test master. Not dead, master has been active.

Somebi commented 8 years ago

Yap still bugged.

 *      {
 *         "name": "players[]",
 *         "in": "formData",
 *         "description": "Players array, consisting of 11 player ids.",
 *         "required": true,
 *         "type": "array",
 *         "items": {
 *              "type":"integer"
 *         },
 *         "collectionFormat":"multi"
 *      }

produces csv

players%5B%5D=3197%2C3517%2C4506%2C4913%2C2798977%2C2799059%2C2799114%2C2799222%2C2799234%2C2799286%2C2799427

Somebi commented 8 years ago

Same example working for query, but not for formData inside in parameter.

Somebi commented 8 years ago

Done it via csv. Anyway ty for your work mate, no offense meant. ;)

fehguy commented 8 years ago

I think you want to use collectionFormat: 'brackets' instead, and use name: 'players' (no [])

can-can commented 8 years ago

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".

multi do not work in formData. What is meaning of brackets? I can't find it in specification

fehguy commented 8 years ago

OK I believe brackets live in implementation but not in the specification (came out after the spec was done). You can see how they work here:

https://github.com/swagger-api/swagger-js/blob/29276f16e9bda75983094d3eeff48e4c6444fe66/test/operation.js#L172-L189

I think you're right, formData does not support them. We can add it.

can-can commented 8 years ago

Thank you @fehguy

fehguy commented 8 years ago

fixed in https://github.com/swagger-api/swagger-ui/commit/efb77652274e99893b11848f02d9dc37d07344aa