Skip to content

Encoding style not respected for requestBody #1470

@sm-Fifteen

Description

@sm-Fifteen

Q&A (please complete the following information)

  • OS: Arch Linux
  • Environment: Firefox 68
  • Method of installation: swagger-editor
  • Swagger-Client version: 3.9.4
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger/OpenAPI definition:

openapi: "3.0.2"
info:
  version: "1.0.0"
  title: "Swagger Petstore"
servers:
  - url: "https://petstore.swagger.io/"
paths:
  /pet:
    post:
      tags:
      - "pet"
      summary: "Add a new pet to the store"
      description: ""
      operationId: "addPet"
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                id:
                  type: string
                  format: uuid
                list:
                  type: array
                  items:
                    type: string
                hashmap:
                  # complex types are stringified to support RFC 1866
                  type: object
                  properties:
                    foo:
                      type: string
                    bar:
                      type: integer
            encoding:
              list:
                style: spaceDelimited
                explode: false
              hashmap:
                style: deepObject
                explode: true
                  
      responses:
        default:
          description: 'Nothing to see here'

Swagger-Client usage:

// Run via swagger-editor

Describe the bug you're encountering

swagger-client does not respect encoding style for complex parameters when inside requestBody. As per the OpenAPI 3.0 specification, complex parameter encoding should follow the encoding parameter and work pretty much the same way as query parameter encoding.

To reproduce...

When submitting a POST request via addPet with the following content:

{
    "id": 1,
    "list": ["a", "b,c"],
    "hashmap": {"foo": "string", "bar": 0}
}

...a request with the following body is sent:

id=1&list=a%2Cb%2Cc&hashmap=%7B%0A%20%20%22foo%22%3A%20%22string%22%2C%0A%20%20%22bar%22%3A%200%0A%7D

This corresponds to hashmap being json-encoded and list in a comma-separated format. No further escaping of the contents will be performed, so if any of the elements in list contain commas, those will be indistinguisable from the element separators. This is despite the encoding field specifying that list should be space-delimited and that hashmap should be rendered as a deep-object.

Expected behavior

For the example given above, the correct serialization method should result in this being sent as the request body:

id=1&list=a%20b%2Cc&hashmap[foo]=string&hashmap[bar]=0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions