Nested Schemas not Rendering Properly
See original GitHub issueQ&A (please complete the following information)
- OS: macOS
- Browser: Chrome
- Method of installation:
pip install swagger-ui-bundle
- Swagger-UI version: 3.20.5
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Broken
{
"openapi": "3.0.0",
"info": {
"title": "API",
"version": "1.0"
},
"servers": [{
"url": "/1.0"
}],
"components": {
"schemas": {
"BaseError": {
"required": [
"code",
"message"
],
"type": "object",
"properties": {
"message": {
"type": "string"
},
"code": {
"type": "integer"
}
}
},
"BaseStringList": {
"type": "array",
"items": {
"type": "string"
}
},
"BaseLink": {
"type": "object",
"properties": {
"rel": {
"type": "string"
},
"href": {
"type": "string",
"format": "uri"
}
}
},
"BaseLinkList": {
"type": "object",
"properties": {
"links": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BaseLink"
}
}
}
},
"BaseTeam": {
"type": "object",
"properties": {
"teamName": {
"type": "string"
}
}
},
"LinkedTeam": {
"allOf": [{
"$ref": "#/components/schemas/BaseTeam"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseTeamList": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LinkedTeam"
}
}
}
},
"LinkedTeamList": {
"allOf": [{
"$ref": "#/components/schemas/BaseTeamList"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseADGroups": {
"type": "object",
"properties": {
"deploy": {
"$ref": "#/components/schemas/BaseStringList"
}
}
},
"BaseVPC": {
"type": "object",
"properties": {
"cidr": {
"type": "string"
}
}
},
"BaseSubnet": {
"type": "object",
"properties": {
"vpc": {
"$ref": "#/components/schemas/BaseVPC"
}
}
},
"BaseRegion": {
"type": "object",
"properties": {
"regionName": {
"type": "string"
},
"subnet": {
"$ref": "#/components/schemas/BaseSubnet"
}
}
},
"BaseRegionList": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BaseRegion"
}
},
"BaseAccountModifiable": {
"type": "object",
"properties": {
"adGroups": {
"$ref": "#/components/schemas/BaseADGroups"
}
}
},
"BaseAccountCreate": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountModifiable"
}, {
"type": "object",
"properties": {
"organizationName": {
"type": "string"
},
"teamName": {
"maxLength": 12,
"minLength": 1,
"type": "string"
}
}
}]
},
"BaseAccount": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountCreate"
}, {
"type": "object",
"properties": {
"regionMapping": {
"$ref": "#/components/schemas/BaseRegionList"
},
"accountName": {
"type": "string"
},
"accountStatus": {
"type": "string"
}
}
}]
},
"LinkedAccount": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccount"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseAccountList": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"LinkedAccountList": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountList"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
}
},
"responses": {
"NotFound": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
},
"Root": {
"description": "List of Routes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseLinkList"
}
}
}
},
"TeamList": {
"description": "List of Teams",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedTeamList"
}
}
}
},
"AccountList": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
},
"Account": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
}
},
"parameters": {
"TeamName": {
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
},
"Environment": {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}
},
"requestBodies": {
"AccountCreate": {
"description": "Account Update JSON",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseAccountCreate"
}
}
},
"required": true
},
"AccountModify": {
"description": "Account Create JSON",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseAccountModifiable"
}
}
},
"required": true
}
}
},
"paths": {
"/": {
"get": {
"summary": "List All Routes",
"operationId": "api.get_list",
"responses": {
"200": {
"description": "List of Routes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseLinkList"
}
}
}
}
}
}
},
"/accounts": {
"get": {
"summary": "List All Accounts",
"operationId": "api.account.get_list",
"responses": {
"200": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
}
}
},
"post": {
"summary": "Create an Account",
"operationId": "api.account.create",
"requestBody": {
"$ref": "#/components/requestBodies/AccountCreate"
},
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
}
}
}
},
"/teams": {
"get": {
"summary": "List All Teams",
"operationId": "api.team.get_list",
"responses": {
"200": {
"description": "List of Teams",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedTeamList"
}
}
}
}
}
}
},
"/teams/{teamName}": {
"get": {
"summary": "List Team Accounts",
"operationId": "api.team.get",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"responses": {
"200": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
}
},
"/teams/{teamName}/{environment}": {
"get": {
"summary": "Get Team Account",
"operationId": "api.account.get",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}, {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
},
"patch": {
"summary": "Update Team Account",
"operationId": "api.account.update",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}, {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"requestBody": {
"$ref": "#/components/requestBodies/AccountModify"
},
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
}
}
}
}
Working
{
"openapi": "3.0.0",
"info": {
"title": "API",
"version": "1.0"
},
"servers": [{
"url": "/1.0"
}],
"paths": {
"/": {
"get": {
"summary": "List All Routes",
"operationId": "api.get_list",
"responses": {
"200": {
"description": "List of Routes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseLinkList"
}
}
}
}
}
}
},
"/accounts": {
"get": {
"summary": "List All Accounts",
"operationId": "api.account.get_list",
"responses": {
"200": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
}
}
},
"post": {
"summary": "Create an Account",
"operationId": "api.account.create",
"requestBody": {
"$ref": "#/components/requestBodies/AccountCreate"
},
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
}
}
}
},
"/teams": {
"get": {
"summary": "List All Teams",
"operationId": "api.team.get_list",
"responses": {
"200": {
"description": "List of Teams",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedTeamList"
}
}
}
}
}
}
},
"/teams/{teamName}": {
"get": {
"summary": "List Team Accounts",
"operationId": "api.team.get",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"responses": {
"200": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
}
},
"/teams/{teamName}/{environment}": {
"get": {
"summary": "Get Team Account",
"operationId": "api.account.get",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}, {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
},
"patch": {
"summary": "Update Team Account",
"operationId": "api.account.update",
"parameters": [{
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}, {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}],
"requestBody": {
"$ref": "#/components/requestBodies/AccountModify"
},
"responses": {
"200": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"404": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"BaseError": {
"required": [
"code",
"message"
],
"type": "object",
"properties": {
"message": {
"type": "string"
},
"code": {
"type": "integer"
}
}
},
"BaseStringList": {
"type": "array",
"items": {
"type": "string"
}
},
"BaseLink": {
"type": "object",
"properties": {
"rel": {
"type": "string"
},
"href": {
"type": "string",
"format": "uri"
}
}
},
"BaseLinkList": {
"type": "object",
"properties": {
"links": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BaseLink"
}
}
}
},
"BaseTeam": {
"type": "object",
"properties": {
"teamName": {
"type": "string"
}
}
},
"LinkedTeam": {
"allOf": [{
"$ref": "#/components/schemas/BaseTeam"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseTeamList": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LinkedTeam"
}
}
}
},
"LinkedTeamList": {
"allOf": [{
"$ref": "#/components/schemas/BaseTeamList"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseADGroups": {
"type": "object",
"properties": {
"deploy": {
"$ref": "#/components/schemas/BaseStringList"
}
}
},
"BaseVPC": {
"type": "object",
"properties": {
"cidr": {
"type": "string"
}
}
},
"BaseSubnet": {
"type": "object",
"properties": {
"vpc": {
"$ref": "#/components/schemas/BaseVPC"
}
}
},
"BaseRegion": {
"type": "object",
"properties": {
"regionName": {
"type": "string"
},
"subnet": {
"$ref": "#/components/schemas/BaseSubnet"
}
}
},
"BaseRegionList": {
"type": "array",
"items": {
"$ref": "#/components/schemas/BaseRegion"
}
},
"BaseAccountModifiable": {
"type": "object",
"properties": {
"adGroups": {
"$ref": "#/components/schemas/BaseADGroups"
}
}
},
"BaseAccountCreate": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountModifiable"
}, {
"type": "object",
"properties": {
"organizationName": {
"type": "string"
},
"teamName": {
"maxLength": 12,
"minLength": 1,
"type": "string"
}
}
}]
},
"BaseAccount": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountCreate"
}, {
"type": "object",
"properties": {
"regionMapping": {
"$ref": "#/components/schemas/BaseRegionList"
},
"accountName": {
"type": "string"
},
"accountStatus": {
"type": "string"
}
}
}]
},
"LinkedAccount": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccount"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
},
"BaseAccountList": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
},
"LinkedAccountList": {
"allOf": [{
"$ref": "#/components/schemas/BaseAccountList"
}, {
"$ref": "#/components/schemas/BaseLinkList"
}]
}
},
"responses": {
"NotFound": {
"description": "Resource was not found",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseError"
}
}
}
},
"Root": {
"description": "List of Routes",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseLinkList"
}
}
}
},
"TeamList": {
"description": "List of Teams",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedTeamList"
}
}
}
},
"AccountList": {
"description": "List of Accounts",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccountList"
}
}
}
},
"Account": {
"description": "An Account",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/LinkedAccount"
}
}
}
}
},
"parameters": {
"TeamName": {
"name": "teamName",
"in": "path",
"description": "The team name.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
},
"Environment": {
"name": "environment",
"in": "path",
"description": "The account environment.",
"required": true,
"style": "simple",
"explode": false,
"schema": {
"type": "string"
}
}
},
"requestBodies": {
"AccountCreate": {
"description": "Account Update JSON",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseAccountCreate"
}
}
},
"required": true
},
"AccountModify": {
"description": "Account Create JSON",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/BaseAccountModifiable"
}
}
},
"required": true
}
}
}
}
Describe the bug you’re encountering
When components
comes before paths
in YAML/JSON specification Schemas are not rendered correctly.
To reproduce…
Steps to reproduce the behavior:
- Copy the
Working
JSON to https://editor.swagger.io/ - Expand
[GET] /teams/{teamName}/{environment}
route. - Examine the Code 200 Example Response or Schema.
- Copy the
Broken
JSON to https://editor.swagger.io/ - Expand
[GET] /teams/{teamName}/{environment}
route. - Examine the Code 200 Example Response or Schema.
Expected behavior
The following attributes should exist in the Schema:
- regionMapping
- accountName
- accountStatus
- links
Additional context or thoughts
I’m using https://github.com/zalando/connexion, when it converts the YAML spec to JSON order is not preserved and components
ends up coming before paths
breaking the Schema rendering.
Also, if the Schema is rendered inside an array then all the attributes show up regardless of where components
is defined.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Swashbuckle nested responses not showing up correctly
The issue I'm having is the response schema isn't showing up correctly if the response has another object within it.
Read more >Nested object data not rendering properly : r/reactjs - Reddit
I feel like this is a basic React thing, but I'm struggling... I am fetching data from firestore and because one field is...
Read more >Specify nested and repeated columns in table schemas
This page describes how to define a table schema with nested and repeated columns in BigQuery. For an overview of table schemas, see...
Read more >how to document nested objects: up to three levels
So far, I have not seen any ability to render the nested objects in the swagger-ui. ... When I click Model Schema, it...
Read more >Understanding JSON Schema
Earlier versions of JSON Schema are not completely ... When you start developing large schemas with many nested and repeated sections, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fixed in swagger-ui@3.36.1
Looks like this has at least some overlap with #4672.