Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submitting Array in requestBody with "application/x-www-form-urlencoded" ignores the explode encoding parameter #4836

Closed
xanoinc opened this issue Aug 27, 2018 · 9 comments

Comments

@xanoinc
Copy link

xanoinc commented Aug 27, 2018

I am attaching an example where explode is set to true in both the parameter block and the requestBody and they behave differently.

The example midway down this page mentions that you can specify the explode param in the encoding block for the requestBody - https://swagger.io/docs/specification/describing-request-body/

I'm using that exact example, except setting explode to true.

0

{
  "openapi" : "3.0.0",
  "info" : {
    "version" : "1.0.0",
    "title" : "Swagger Petstore",
    "license" : {
      "name" : "MIT"
    }
  },
  "servers" : [ {
    "url" : "http://petstore.swagger.io/v1"
  } ],
  "paths" : {
    "/pets" : {
      "post" : {
        "summary" : "Create a pet",
        "operationId" : "createPets",
        "tags" : [ "pets" ],
        "parameters" : [
          {
            "name" : "limit",
            "in" : "query",
            "description" : "How many items to return at one time (max 100)",
            "required" : false,
            "schema" : {
              "type" : "array",
              "items" : {
                "type": "string"
              }
            },
            "style": "form",
            "explode": true
          }
        ],
        "requestBody" : {
          "content" : {
            "application/x-www-form-urlencoded" : {
              "schema" : {  
                "type" : "object",
                "properties" : {
                  "color" : {
                    "type" : "array",
                    "items" : {
                      "type" : "string"
                    }
                  }
                }
              },
              "encoding" : {
                "color" : {
                  "style" : "form",
                  "explode" : true
                }
              }
            }
          }
        },
        "responses" : {
          "201" : {
            "description" : "Null response"
          }
        }
      }
    }
  }
}
@shockey
Copy link
Contributor

shockey commented Aug 28, 2018

Hi @seanmetrix, behind the scenes this is because we don't have support for encoding yet - the parameter is working because you can define style/explode without using encoding.

@xanoinc
Copy link
Author

xanoinc commented Aug 28, 2018

How do you define define style/explode in the requestBody without using encoding?

@shockey
Copy link
Contributor

shockey commented Sep 27, 2018

@seanmetrix, afaik you can't 😞

@xyfantis
Copy link

xyfantis commented Mar 6, 2019

@shockey any update on this?

@shockey
Copy link
Contributor

shockey commented Apr 5, 2019

@xyfantis nothing yet!

@jnpwly
Copy link

jnpwly commented Nov 26, 2019

Is there anything we (maybe even, I) can do for this?

@webron
Copy link
Contributor

webron commented Nov 26, 2019

@jnpwly of course! Submitting PRs always helps! :)

@carlosvega
Copy link

Any progress? Right now I don't see how could I define a POST path with an array parameter.

The following definition:

requestBody:
        content:
          application/x-www-form-urlencoded:
            schema: 
              properties:
                entity:
                  description: entity as ontology code
                  type: array
                  example: ["DOID:2841", "ENSP00000363868"]
                  items:
                    type: string
                limit:
                  $ref: '#/components/parameters/limit'
                format:
                  $ref: '#/components/parameters/format'
                entity_types:
                  $ref: '#/components/parameters/entity_types'
            encoding:
              entity:
                style: form
                explode: true

It's generating this:

curl -X POST "https://localhost/getCooccurrence/" -H "Content-Type: application/x-www-form-urlencoded" -d "entity=DOID%3A2841%2CENSP00000363868"

instead of

curl -X POST "https://localhost/getCooccurrence/" -H "Content-Type: application/x-www-form-urlencoded" -d "entity=DOID%3A2841&entity=2CENSP00000363868"

@hkosova
Copy link
Contributor

hkosova commented Jul 23, 2020

encoding is supported in Swagger UI 3.26.1 and later.
PR: swagger-api/swagger-js#1500

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants