swagger-js
swagger-js copied to clipboard
Deep object model render impacted by definitions + paths ordering in v2 doc
Q&A (please complete the following information)
- OS: Windows 10
- Environment: Chrome 72.0.3626.109
- Method of installation: npm
- Swagger-Client version: 3.8.23
- Swagger/OpenAPI version: Swagger 2.0
- Swagger-UI version: 3.20.7
Content & configuration
Swagger/OpenAPI definition: Doc with 'definitions' before 'paths' renders incorrectly:
{
"swagger": "2.0",
"info": {
"title": "Bug Repro",
"version": "1.0.0",
"description": ""
},
"host": "localhost",
"schemes": [
"https"
],
"definitions": {
"SampleDefinitionA": {
"type": "object",
"properties": {
"someProperty": {
"$ref": "#/definitions/SampleDefinitionB"
}
}
},
"SampleDefinitionB": {
"type": "object",
"properties": {
"parentOfAllOf": {
"allOf": [
{
"$ref": "#/definitions/SampleEnum"
}
],
"description": "Some description of the enum"
}
}
},
"SampleEnum": {
"type": "string",
"enum": [
"ValueA",
"ValueB"
]
}
},
"paths": {
"/sample": {
"get": {
"operationId": "Sample",
"summary": "Sample",
"description": "Sample definition",
"responses": {
"200": {
"description": "Some description",
"schema": {
"$ref": "#/definitions/SampleDefinitionA"
}
}
}
}
}
}
}
Same doc with 'paths' before 'definitions' renders correctly:
{
"swagger": "2.0",
"info": {
"title": "Bug Repro",
"version": "1.0.0",
"description": ""
},
"host": "localhost",
"schemes": [
"https"
],
"paths": {
"/sample": {
"get": {
"operationId": "Sample",
"summary": "Sample",
"description": "Sample definition",
"responses": {
"200": {
"description": "Some description",
"schema": {
"$ref": "#/definitions/SampleDefinitionA"
}
}
}
}
}
},
"definitions": {
"SampleDefinitionA": {
"type": "object",
"properties": {
"someProperty": {
"$ref": "#/definitions/SampleDefinitionB"
}
}
},
"SampleDefinitionB": {
"type": "object",
"properties": {
"parentOfAllOf": {
"allOf": [
{
"$ref": "#/definitions/SampleEnum"
}
],
"description": "Some description of the enum"
}
}
},
"SampleEnum": {
"type": "string",
"enum": [
"ValueA",
"ValueB"
]
}
}
}
Swagger-Client usage: As used in the Swagger UI v3.20.7
Describe the bug you're encountering
A v2 document with complex nested models and 'definitions' before 'paths' does not correctly render the fully-expanded model in the Swagger UI. This is because the resolved subtree for the model is not correct in this case. While the 'normal' order is certainly 'paths' before 'definitions', per the spec, order should not matter.
To reproduce...
Steps to reproduce the behavior:
- View the given document with 'definitions' before 'paths' in the Swagger UI.
- Expand the 200 response model all the way, as in the attached screenshot. Note that the model is not rendered correctly.
Expected behavior
The 'allOf' should be correctly expanded like in the document with 'paths' before 'definitions'. See the attached screenshot. The Swagger UI renders incorrectly because the resolved subtree for the response is incorrect:
responses: {
'200': {
description: 'Some description',
schema: {
type: 'object',
properties: {
someProperty: {
type: 'object',
properties: {
parentOfAllOf: {
allOf: [
{
type: 'string',
'enum': [
'ValueA',
'ValueB'
],
$$ref: '#/definitions/SampleEnum'
}
],
description: 'Some description of the enum'
}
},
$$ref: '#/definitions/SampleDefinitionB'
}
},
$$ref: '#/definitions/SampleDefinitionA'
}
}
}
The correct resolved subtree (from the document with 'paths' before 'definitions'):
responses: {
'200': {
description: 'Some description',
schema: {
type: 'object',
properties: {
someProperty: {
type: 'object',
properties: {
parentOfAllOf: {
type: 'string',
'enum': [
'ValueA',
'ValueB'
],
description: 'Some description of the enum'
}
},
$$ref: '#/definitions/SampleDefinitionB'
}
},
$$ref: '#/definitions/SampleDefinitionA'
}
}
}
Screenshots
Correct rendering with 'definitions' before 'paths':
Incorrect rendering with 'paths' before 'definitions':
Additional context or thoughts
Seems like this bug may be related to https://github.com/swagger-api/swagger-js/issues/1394.
🤨
Odd. I'll dig into this!