swagger-ui
swagger-ui copied to clipboard
JSON query parameter accepting array of objects is stringified twice
Q&A (please complete the following information)
- Swagger-UI version: (Version on https://editor-next.swagger.io)
- Swagger/OpenAPI version: 3.1.0
Content & configuration
Example Swagger/OpenAPI definition:
{
"openapi": "3.1.0",
"info": {
"title": "Server",
"version": "0.0.1"
},
"paths": {
"/endpoint": {
"get": {
"responses": {
},
"parameters": [
{
"name": "param",
"in": "query",
"description": "a param that accepts an array of objects",
"content": {
"application/json": {
"schema": {
"type": "array",
"maxItems": 10,
"items": {
"type": "object",
"properties": {
"a": {
"type": "string"
},
"b": {
"type": "number"
}
}
}
}
}
}
}
]
}
}
}
}
Describe the bug you're encountering
The above query parameter produces an encoded URI string that was JSON-stringified twice.
To reproduce...
Steps to reproduce the behavior:
- Go to https://editor-next.swagger.io
- Copy and paste the OpenAPI spec
- Expand the endpoint definition on the UI and click [Try it out]
- Click [Add object item]
- Click [Execute]
- Inspect the generated URL
Expected behavior
Expected the following URL, encodes [{\n "a": "string",\n "b": 0\n}]
https://raw.githubusercontent.com/endpoint?param=
%5B%7B%0A%20%20%22a%22%3A%20%22string%22%2C%0A%20%20%22b%22%3A%200%0A%7D%5D
Actual behavior
Object is JSON-stringified twice. The generated URL encodes ["{\\n \\"a\\": \\"string\\",\\n \\"b\\": 0\\n}"], i.e., a JSON string in a JSON array.
https://raw.githubusercontent.com/endpoint?param=
%5B%22%7B%5Cn%20%20%5C%22a%5C%22%3A%20%5C%22string%5C%22%2C%5Cn%20%20%5C%22b%5C%22%3A%200%5Cn%7D%22%5D