Skip to content

Form request body with array value does not use default 'explode' property #2713

@phillipuniverse

Description

@phillipuniverse

Q&A (please complete the following information)

Content & configuration

Plug in the below yaml into https://editor.swagger.io/

Swagger/OpenAPI definition:

openapi: 3.0.2
info:
  title: Tempus Docs
  version: 0.1.0
paths:
  /withlistparams:
    post:
      summary: With List Params
      operationId: with_list_params_withlistparams_post
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Body_with_list_params_withlistparams_post'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
components:
  schemas:
    Body_with_list_params_withlistparams_post:
      title: Body_with_list_params_withlistparams_post
      required:
      - vals
      type: object
      properties:
        vals:
          title: Vals
          type: array
          items:
            type: string

Swagger-Client usage:
N/A

Describe the bug you're encountering

When I go to 'Try it Out' on the '/withlistresponse' operation and fill out items for the vals array, I get the default serialization behavior of csv in the request:

image

I believe that this is a misinterpretation of the default value of the style keyword within the encoding for a request body specified in the OpenAPI spec.

There appears to be no default set for the style field in swagger-ui (most recently this would have been from ##1500). The default value of style should be form, relevant part from the linked spec (emphasis mine):

Describes how a specific property value will be serialized depending on its type. See Parameter Object for details on the style property. The behavior follows the same values as query parameters, including default values

If you look at the parameterStyle property, the spec states:

Default values (based on value of in): for query - form;

If I take my example above and modify it slightly, you can see then that these 2 yaml snippets should be the exact same behavior:

Original:

      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Body_with_list_params_withlistparams_post'
        required: true

Output is CSV:

image

style: form, output is effectively explode: true with repeated parameters:

      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Body_with_list_params_withlistparams_post'
            encoding:
              vals:
                style: form
        required: true

image

To reproduce...

Steps to reproduce the behavior:

  1. Specify a form request body with a schema that contains an array field
  2. Go to 'Try it Out'
  3. Populate the array field with some values
  4. Hit 'Execute'
  5. See the request uses a csv for the array value (effectively explode: false in the encoding)

Expected behavior

The defaults from the OpenAPI specification are respected

Screenshots

Given above

Additional context or thoughts

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