Open RaviVaranasi opened 2 years ago
@RaviVaranasi that is not a issue with swagger that error tells you really detailed everything about your error.
a circular repeating fild in a Object can not get serialized to JSON it is infinit the workaround is to get Infinity amount of Ram and Harddisk and try to find the end of Infinity
My apologies got the wrong stacktrace
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Object'
| property 'properties' -> object with constructor 'Object'
| property 'children' -> object with constructor 'Object'
--- property 'items' closes the circle
at JSON.stringify (<anonymous>)
at stringify (/Users/projects/<project>/node_modules/swagger-ui-express/index.js:241:19)
at generateHTML (/Users/projects/<project>/node_modules/swagger-ui-express/index.js:176:73)
at /Users/projects/<project>/node_modules/swagger-ui-express/index.js:184:21
Below is code change in index.js
to work around this issue. Happy to issue a PR
var stringify = function (obj, prop) {
var placeholder = '____FUNCTIONPLACEHOLDER____'
var fns = []
var seen = new WeakSet();
var json = JSON.stringify(obj, function (key, value) {
if (typeof value === 'function') {
fns.push(value)
return placeholder
}
if (typeof value === "object" && value !== null) {
if (seen.has(value)) {
return;
}
seen.add(value);
}
return value
}, 2)
json = json.replace(new RegExp('"' + placeholder + '"', 'g'), function (_) {
return fns.shift()
})
return 'var options = ' + json + ';'
}
@RaviVaranasi the Changes look good to me at first view simply do the pr and maybe add a test for that case also thanks a lot i did not fully understand it before i tought the problem is a diffrent
I have an object that has children of the same type.
Below is the error message
Is there a way to work around this issue?