Repository navigation
Response model expand/collapse does not work on initial render with OAS 3.1 #10628
Description
Q&A (please complete the following information)
- OS: macOS
- Browser: chrome
- Version: 142
- Method of installation: npm
- Swagger-UI version: 5.30.2
- Swagger/OpenAPI version: OpenAPI 3.1
Content & configuration
Example Swagger/OpenAPI definition:
{
"openapi": "3.1.0",
"info": {
"version": "1.0.0",
"title": "Swagger Petstore",
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
}
},
"servers": [
{
"url": "http://petstore.swagger.io/v1"
}
],
"paths": {
"/pets": {
"get": {
"summary": "List all pets",
"operationId": "listPets",
"tags": ["pets"],
"parameters": [
{
"name": "limit",
"in": "query",
"description": "How many items to return at one time (max 100)",
"required": false,
"schema": {
"type": "integer",
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "A paged array of pets",
"headers": {
"x-next": {
"description": "A link to the next page of responses",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pets"
}
}
}
},
"default": {
"description": "unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Error"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Pet": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"Pets": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Pet"
}
},
"Error": {
"type": "object",
"required": ["code", "message"],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
}Swagger-UI configuration options:
SwaggerUI({
defaultModelRendering: "model"
})Describe the bug you're encountering
To reproduce...
Steps to reproduce the behavior:
- Render any Open API 3.1 spec with
defaultModelRendering: "model"configuration - Click on an operation to expand it and show the Responses section
- In the "Schema" section, click on any part of the model that should expand/collapse
- Observe that clicking does nothing
- Click "Example Value" to toggle to the example view
- Click "Schema" to toggle back to the schema view
- Observe that expanding/collapsing the model now works
Expected behavior
When the "Schema" view is rendered by default (defaultModelRendering: "model"), the expand/collapse should work
Additional context or thoughts
The bug only seems to present itself when using OAS 3.1. Using OAS 3.0 or earlier does not exhibit the same problem.
I suspect that the problem could be here:
swagger-ui/src/core/plugins/json-schema-2020-12/hooks.js
Lines 110 to 116 in 7f75ee3
| useEffect(() => { | |
| pathMutator( | |
| parentState === JSONSchemaIsExpandedState.DeeplyExpanded | |
| ? JSONSchemaIsExpandedState.DeeplyExpanded | |
| : isExpandedState | |
| ) | |
| }, [parentState]) |
This effect depends on pathMutator, parentState and isExpandedState, but the dependencies array only includes [parentState]. This means that the initial value of isExpandedState is captured when the effect runs on initial render, but the effect won't re-run if that value later changes.
Activity
scottohara commentedon Mar 31, 2026
Confirming that this is still an issue in Swagger UI v5.32.1 (see the steps above, it should be reasonably trivial for anyone to reproduce).
The linked PR #10639 addresses the bug, but has been awaiting review for some time.
Would greatly appreciate any maintainer who can spare some time to review and approve this PR. Thanks in advance.
scottohara commentedon Jun 1, 2026
Confirming that this is still an issue in Swagger UI v5.32.6 (see the steps above, it should be reasonably trivial for anyone to reproduce).
The linked PR #10639 addresses the bug, but has been awaiting review for some time.
Would greatly appreciate any maintainer who can spare some time to review and approve this PR. Thanks in advance.
alkismavridis commentedon Jun 30, 2026
Also affected. The error happens randomly so the hypothesis of a race condition seems to be accurate. Do we have any news on the issue?
alkismavridis commentedon Jun 30, 2026
As a workaround, we click on "Example Value", then back on "Schema" and then it works.
scottohara commentedon Sep 14, 2026
It would appear that this issue can no longer be reproduced using the latest unreleased version in
main.It seems that the work done for #11019 has also resolved this issue, and I would expect it to be fixed for users in the next release (whether that's
v15.32.16orv15.33.0).