Swagger-ui: Submitting Array in requestBody with "application/x-www-form-urlencoded" ignores the explode encoding parameter

Created on 28 Aug 2018  路  9Comments  路  Source: swagger-api/swagger-ui

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"
          }
        }
      }
    }
  }
}
P2 try-it-out 3.x feature

Most helpful comment

@shockey any update on this?

All 9 comments

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.

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

@seanmetrix, afaik you can't 馃槥

@shockey any update on this?

@xyfantis nothing yet!

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

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

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"

encoding is supported in Swagger UI 3.26.1 and later.
PR: https://github.com/swagger-api/swagger-js/pull/1500

Was this page helpful?
0 / 5 - 0 ratings