Comments (4)
The issue on the surface looks like it was introduced by 7300e6c but it seems like it actually uncovered a different issue, which you can see in Swagger Editor.
The names there are displayed correctly:
but if we actually expand the schemas:
you can see that additionalData
from FirstOneOf is missing and the references are also not resolved properly.
The resolved subtree for OneOfParent:
{
"title": "OneOfParent",
"properties": {
"additionalData": {
"oneOf": [
{
"$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/OneOfParent",
"properties": {
"numberProp": {
"type": "number",
"example": "1"
}
},
"type": "object",
"title": "FirstOneOf",
"$$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/FirstOneOf"
},
{
"$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/OneOfParent",
"properties": {
"person": {
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object",
"title": "SecondOneOf",
"$$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/SecondOneOf"
},
{
"$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/OneOfParent",
"properties": {
"person": {
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"surname": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object",
"title": "ThirdOneOf",
"$$ref": "http://localhost:3200/examples/regressionJson.json#/components/schemas/ThirdOneOf"
}
]
}
},
"type": "object"
}
We can see both the resolved $$ref
and unresolved $ref
- because of this the names are different and we only get the schema under $ref
, as that was one of the changes in this commit 7300e6c
If we expand FirstOneOf first and then OneOfParent, we'll get this:
This looks to me like an issue with the resolver - perhaps with allOf and circular / unresolved references.
from swagger-ui.
In theory, we could pass fn
to our Model
component and use mergeJsonSchema
- in place of
swagger-ui/src/core/components/model.jsx
Lines 72 to 82 in 6e91056
have something like this:
if ($ref) {
const refName = this.getModelName($ref)
const refSchema = this.getRefSchema(refName)
if (Map.isMap(refSchema)) {
schema = fromJS(fn.mergeJsonSchema(schema.toJS(), refSchema.toJS()))
name = name || refName
if (!$$ref) {
schema = schema.set("$$ref", $ref)
$$ref = $ref
}
} else if (!$$ref) {
schema = null
name = $ref
}
}
this will work for the spec in the issue:
But it will not solve it for cases where we have more than one circular reference, as the $ref
property will get replaced by the next defined $ref
. To illustrate it, we can have this spec:
{
"openapi": "3.0.0",
"info": {
"title": "Test",
"description": "Test",
"license": {
"name": "Apache 2.0",
"url": "https://www.apache.org/licenses/LICENSE-2.0.html"
},
"version": "1.0"
},
"servers": [
{
"url": "https://localhost:8000"
}
],
"components": {
"schemas": {
"Parent": {
"title": "Parent",
"properties": {
"parentData": {
"$ref": "#/components/schemas/OneOfParent"
}
},
"type": "object"
},
"OneOfParent": {
"title": "OneOfParent",
"properties": {
"additionalData": {
"oneOf": [
{
"$ref": "#/components/schemas/FirstOneOf"
}
]
}
},
"type": "object"
},
"FirstOneOf": {
"title": "FirstOneOf",
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/Parent"
},
{
"$ref": "#/components/schemas/OneOfParent"
},
{
"properties": {
"numberProp": {
"type": "number",
"example": "1"
}
},
"type": "object"
}
]
}
}
}
}
and our rendered model will be missing parentData
:
If we swap the order of references in allOf
in FirstOneOf
:
"FirstOneOf": {
"title": "FirstOneOf",
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/OneOfParent"
},
{
"$ref": "#/components/schemas/Parent"
},
{
"properties": {
"numberProp": {
"type": "number",
"example": "1"
}
},
"type": "object"
}
]
}
This time additionalData
will be missing:
It looks to me like we would somehow need to keep these unresolved $refs
in an array (as $ref: [<unresolved_ref_0>, <unresolved_ref_1>, ...]
) instead of only having a string there, that gets replaced when we get another $ref
from swagger-ui.
- we will assume that every schema with $ref field and one or more additional fields is a result of allOf keyword merge
- given that Reference Object cannot have any additional fields than $ref, the assumption is almost correct
- we will use Immutable.mergeDeep to merge the referenced schema with the referencing one (which makes it compatible with swagger-client
allOf
specmap plugin) - this can introduce possible circular references (cycles) again into the deferenced tree
from swagger-ui.
Addressed in #9794
from swagger-ui.
Related Issues (20)
- Resolver error: Could not resolve reference: Could not resolve pointer:
- Swagger UI not showing on vercel? I have a solution here it is HOT 1
- Only first path parameter is replaced in "Try it out" HOT 4
- ramda-adjunct tried to access ramda HOT 5
- Addition of audience parameter to oauth config
- OpenAPI 3.1.: examples in webhooks are being overwritten by the examples in schema HOT 4
- [OpenAPI 3.1] Example value is not generated for nested objects that are referenced via allOf HOT 11
- Add missing default configuration options HOT 6
- CSS source map is broken HOT 1
- operation level server override option always appears for OAS 3.1 specification HOT 2
- No name property is assigned to "Server" Combobox.
- 5.17.12 HOT 1
- Add a dark mode for the page
- swagger-ui-react: spec does not update on prop change and resets to default on page refresh HOT 1
- Path Parameter is not being passed through Request URL and Curl Command. HOT 3
- UI css scrambled
- Ensures the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds (.btn-primary)
- Swagger-UI DownloadURL autocomplete
- Resolver error at $ref Could not resolve reference: JSON Pointer evaluation failed while evaluating token "paths" against an unexpected Element
- Idk
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swagger-ui.