swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

multi-value parameters passed differently for multipart/form-data

Open aalleexxeeii opened this issue 8 years ago • 6 comments

When multipart/form-data is specified as content type, multi-value parameters are formatted as a single parameter with a strange representation (quoted and comma-separated) rather than multiple sections with the same name and raw body.

Try this parameter definition with the latest version deployed on petstore

        required: true
        type: array
        items:
          type: string
        collectionFormat: multi

aalleexxeeii avatar Jul 31 '17 15:07 aalleexxeeii

Related to #1657 ?

cheerfulstoic avatar Sep 25 '17 15:09 cheerfulstoic

I've the same problem.

mariomka avatar Apr 02 '18 16:04 mariomka

Looking at this again, the spec actually doesn't really define the behavior well when using multipart/form-data and the intended use was for application/x-www-form-urlencoded. Not really sure how to resolve this one.

webron avatar Jun 05 '18 20:06 webron

The next version of the spec, OpenAPI 3.1, will support the style and explode attributes for multipart/form-data that can be used to control array serialization. I.e. whether to send the array as a single field with comma-separated values, or as multiple fields (one per value).

hkosova avatar Jul 03 '20 18:07 hkosova

the spec actually doesn't really define the behavior well

What the spec says is:

Form parts with identical field names MUST NOT be coalesced.

https://tools.ietf.org/html/rfc7578#section-5.2

Multiple repeated sections is what browsers send, so maybe that should be the default.

kernc avatar Jan 12 '21 08:01 kernc

Got the same issue. Using encoding block, I was able to solve the issue. Instead of getting -F column=value1,value2, I now get -F column=value1 -F column=value2 in generated CURL calls. Below an excerpt for people with the issue. Deduced from OpenAPI v3.1 spec https://spec.openapis.org/oas/latest.html#encoding-object-example

  /search/csv:
    post:
      requestBody:
        required: true
        content:
          multipart/form-data:
            encoding:
              column:
                explode: true
              result_columns:
                explode: true
            schema:
              type: object
              required: ["data"]
              properties:
                column:
                  description: "Par défaut, toutes les colonnes sont concaténées pour constituer l’adresse qui sera géocodée. On peut définir les colonnes à utiliser via ce paramètre"
                  type: array
                  items:
                    type: string
                result_columns:
                  description: "Champs attendus dans la réponse"
                  type: array
                  items:
                    type: string
                data:
                  description: "Le fichier doit être un CSV dont la taille ne doit pas excéder 50 Mo"
                  type: string
                  format: binary

ThomasG77 avatar Jan 09 '24 17:01 ThomasG77