-
Notifications
You must be signed in to change notification settings - Fork 9.1k
v3 - Resolver error - Cannot read property '1' of undefined #3366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah, this is due to the circular reference. |
This could be related to: #3051 |
I have the same problem defining a tree structure. It's very disconcerting when the first thing a user sees at http://www.genetrees.org is an obscure error message. Is there a way to suppress the error message? See the TreeNode definition here |
@webron Does your comment above mean that circular references are not allowed? Our spec requires the use of a circular reference. |
Seems like the error might be: swagger-api/swagger-js#1077 |
Need to be able to remove error messages. For whatever reason, it might not be something that's easily fixable, or just something that the resolver can't handle correctly. |
@stoutfiles if hiding the error is all want, try a custom css:
|
@heldersepu, good thinking! @stoutfiles, alternatively, if modifying JS is more your speed, here are a pair of Swagger-UI plugins that will hide resolver errors or hide all errors: // hide errors that come from the resolver
const HideResolverErrorsPlugin = () => {
return {
statePlugins: {
err: {
wrapSelectors: {
allErrors: (ori) => () => {
return ori().filter(err => err.get("source") !== "resolver")
}
}
}
}
}
}
// hide the entire Errors container
const HideAllErrorsPlugin = () => {
return {
wrapComponents: {
errors: () => () => null
}
}
} |
We added the suggested plugin above, and it gets around the immediate problem. I'd like to see something in swagger-js that will not cause an error for this particular case in the first place. |
I've got a similar problem with
Note: my problem was solved with Swagger UI 3.11.0, example now works fine. |
One of our users has hit this issue, and interestingly it only seems to occur if the object with the circular reference ( To explain, here's an example that causes a {
"swagger": "2.0",
"info": {
"title": "Test API"
},
"basePath": "/",
"paths": {
"/test": {
"get": {
"responses": {
"200": {
"schema": {
"$ref": "#/definitions/List"
}
}
}
}
}
},
"definitions": {
"List": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
}
},
"Item": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
}
}
}
}
}
} And here is a functionally equivalent version, that doesn't exhibit the error. The only difference is simply that the {
"swagger": "2.0",
"info": {
"title": "Test API"
},
"basePath": "/",
"paths": {
"/test": {
"get": {
"responses": {
"200": {
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
}
}
}
}
}
}
},
"definitions": {
"Item": {
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
}
}
}
}
}
} |
Actually, it may not be the circular reference at all. I suspect it is something to do with the number of levels being traversed when resolving. Here is another reduced test case that also gets a In total, there are 4 levels to get down to the leaf
{
"swagger": "2.0",
"paths": {
"/list": {
"put": {
"parameters": [
{
"$ref": "#/parameters/list"
}
]
}
}
},
"parameters": {
"list": {
"name": "list",
"in": "body",
"schema": {
"$ref": "#/definitions/List"
}
}
},
"definitions": {
"List": {
"type": "object",
"properties": {
"items": {
"$ref": "#/definitions/Items"
}
}
},
"Items": {
"type": "array",
"items": {
"$ref": "#/definitions/Item"
}
},
"Item": {
"type": "object",
"properties": {
"itemId": {
"type": "string"
}
}
}
}
} |
When working with a similar example I found that removing forward references in the definitions removed the error. ie declare 'Item' then 'Items' then 'List'. Same definitions.. just change in order. Obviously this is not a real fix as you want to order your object definitions in a more accessible manner but perhaps it might assist in locating the issue in the resolver code? Perhaps the issue is the number of forward references, as @scottohara points out, collapsing references into inline definitions also removes the error message. Here is the above definition from @scottohara reordered, and not showing the unexpected errror. { "swagger": "2.0", "info": { "version": "0", "title": "No forward references", "description": "sample" }, "paths": { "/list": { "put": { "parameters": [ { "$ref": "#/parameters/list" } ], "responses": { "200": { "$ref": "#/responses/OK" } } } } }, "parameters": { "list": { "name": "list", "in": "body", "schema": { "$ref": "#/definitions/List" } } }, "responses": { "OK": { "description": "200 OK" } }, "definitions": { "Item": { "type": "object", "properties": { "itemId": { "type": "string" } } }, "Items": { "type": "array", "items": { "$ref": "#/definitions/Item" } }, "List": { "type": "object", "properties": { "items": { "$ref": "#/definitions/Items" } } } } } |
This PR (swagger-api/swagger-js#1243) seems to also confirm that order of references can workaround the issue ( |
I'm happy to report that Swagger UI v3.12.0 (presumably this specific fix: #4273) now correctly resolves two examples above that were previously failing with |
Closing as resolved. |
This error occured when we upgraded to swagger ui 3.x.
We use
[email protected]
.The issue can be reproduced with the following swagger-spec on Swagger Editor:
The text was updated successfully, but these errors were encountered: