swagger-api / swagger-api/swagger-ui
Misleading example value in case of cyclic references
@DipakHalkude is already working on this.
Since Oct 30, 2025.
- 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: macOS
- Browser: chrome
- Version: 135.0.7049.114
- Method of installation: npm
- Swagger-UI version: 5.20.5
- Swagger/OpenAPI version: Swagger 2.0
Content & configuration
Example Swagger/OpenAPI definition:
{
"swagger": "2.0",
"paths": {
"/A": {
"get": {
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/A"
}
}
}
}
}
},
"definitions": {
"A": {
"type": "object",
"properties": {
"nextA": {
"$ref": "#/definitions/A"
}
}
}
}
}
Swagger-UI configuration options:
SwaggerUI({
spec: apiSpec,
dom_id: '#api-ui-container',
defaultModelRendering: 'model',
showExtensions: true,
deepLinking: true,
plugins: [DisableTryItOutPlugin],
});
Describe the bug you're encountering
To reproduce...
Steps to reproduce the behavior:
Go to Example value of the only endpoint. You will see that it is:
{
"nextA": "string"
}
Although the nextA is really an object that follows the same definition, like in
{
"nextA": {
"nextA": {}
}
}
Of course in any given value the nextAs must stop at some recursion level, therefore the Swagger UI would have to decide how many levels to include in the example value. But showing a "string" instead is misleading.
Expected behavior
Even an empty object would make more sense. Please display something better than just a string.
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.
Assessment
This issue has not been assessed yet.