Skip to content

Wrong encoding used for deepObject fields in request bodies #7734

@adriangb

Description

@adriangb

Example OpenAPI schema:

openapi: 3.0.3
info:
  title: API
  version: 0.1.0
paths:
  /deep:
    post:
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Outer'
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              properties:
                data:
                  $ref: '#/components/schemas/Outer'
            encoding:
              data:
                style: deepObject
                explode: true
        required: true
components:
  schemas:
    Inner:
      title: Inner
      required:
        - foo
      type: object
      properties:
        foo:
          title: Foo
          type: integer
    Outer:
      title: Outer
      required:
        - inner
        - bar
      type: object
      properties:
        inner:
          $ref: '#/components/schemas/Inner'
        bar:
          title: Bar
          type: number

Input:

{
  "inner": {
    "foo": 0
  },
  "bar": 0
}

curl produced by Swagger UI for the input:

curl -X 'POST' \
  'http://127.0.0.1:8000/deep' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'data=%7B%0A%20%20%22inner%22%3A%20%7B%0A%20%20%20%20%22foo%22%3A%200%0A%20%20%7D%2C%0A%20%20%22bar%22%3A%200%0A%7D'

It looks like the payload is url-encoded JSON. I believe the correct request should be:

curl -X 'POST' \
  'http://127.0.0.1:8000/deep' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'data[inner][foo]=0' \
  -d 'data[bar]=0'

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions