-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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.