swagger-api / swagger-api/swagger-ui
GET parameters not exploded when `"in": "query","style": "form","explode": true` and the request can be `oneOf` a few different objects
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Ubuntu 20.04
- Browser: Chrome
- Version: 125.0.6422.113
- Method of installation: dist assets
- Swagger-UI version: 5.17.14
- Swagger/OpenAPI version: OpenAPI 3.1
Content & configuration
Example Swagger/OpenAPI definition:
{
"openapi": "3.1.0",
"servers": [
{
"description": "Petstore Swagger API",
"url": "https://petstore.swagger.io/v2"
}
],
"info": {
"description": "This is a sample Petstore API.",
"version": "1.0",
"title": "Petstore",
"contact": {
"email": "apiteam@swagger.io",
"name": "Swagger API Team"
},
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0"
}
},
"paths": {
"/petsearch": {
"get": {
"tags": ["pet"],
"security": [{}],
"summary": "Everything about your Pets",
"operationId": "retrievePetGET",
"description": "Returns a list of available pets that fit your desires",
"parameters": [
{
"in": "query",
"name": "parameters",
"style": "form",
"explode": true,
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/RequestBody"
}
]
}
}
],
"responses": {
"200": {
"description": "OK: available pets that correspond with your criteria",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
},
"application/yaml": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"RequestBody": {
"type": "object",
"title": "Pet Search Request",
"description": "Search for a pet that correponds to certain criteria",
"additionalProperties": false,
"properties": {
"animal": {
"type": "string",
"enum": ["dog", "cat", "bird"]
},
"color": {
"type": "string",
"enum": ["black", "white", "multicolored"]
}
},
"required": ["animal"]
},
"Pets": {
"type": "array",
"items": {
"type": "object",
"properties": {
"animal": {
"type": "string",
"enum": ["cat", "dog", "bird"]
},
"color": {
"type": "string",
"enum": ["black", "white", "multicolored"]
}
}
}
}
}
}
}
Swagger-UI configuration options:
const ui = SwaggerUIBundle({
url: "openapi.json",
dom_id: "#swagger-ui",
deepLinking: true,
requestSnippetsEnabled: true,
requestSnippets: {
generators: {
curl_bash: {
title: "cURL (bash)",
syntax: "bash",
default: true,
},
curl_powershell: {
title: "cURL (PowerShell)",
syntax: "powershell",
},
curl_cmd: {
title: "cURL (CMD)",
syntax: "bash",
},
},
defaultExpanded: true,
languages: ["curl_bash", "curl_powershell", "curl_cmd"],
},
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
plugins: [SwaggerUIBundle.plugins.DownloadUrl],
layout: "StandaloneLayout",
});
?animal=dog&color=black
Describe the bug you're encountering
The parameters are expanded just fine if there is only one possible request object. But if you have more than one "type" of request that can be formulated, and you express this with a oneOf, the parameters are no longer expanded / exploded. The whole object is simply serialized as the value of the named parameter. Even if there is only a single object inside the oneOf the exploding still gets messed up.
To reproduce...
Here's a live example on codesandbox.
Steps to reproduce the behavior in the live example on codesandbox:
- Expand the
GEToperation in right preview panel - Click on
Try it out - Click on
Execute - In the request snippets you will see that the parameters are not exploded but simply serialized as a single object
Expected behavior
The parameters should be exploded / expanded even when there are multiple "types" to choose from that are defined in an anyOf.
Screenshots
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in the linked CodeSandbox and then trace the request-snippet query serialization path in Swagger UI. Verify the OpenAPI 3.1 example with a query parameter using form style, explode true, and oneOf produces separate animal and color query parameters rather than serializing the object under parameters.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100