swagger-js
swagger-js copied to clipboard
Form request body with array value does not use default 'explode' property
Q&A (please complete the following information)
- OS: macOS
- Environment: Chrome
- Method of installation: none - using https://editor.swagger.io/
- Swagger-Client version: 3.25.5
- Swagger/OpenAPI version: OpenAPI 3.0
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:
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 #https://github.com/swagger-api/swagger-js/pull/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:
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
To reproduce...
Steps to reproduce the behavior:
- Specify a form request body with a schema that contains an array field
- Go to 'Try it Out'
- Populate the array field with some values
- Hit 'Execute'
- See the request uses a csv for the array value (effectively
explode: falsein the encoding)
Expected behavior
The defaults from the OpenAPI specification are respected
Screenshots
Given above