json-schema-tools
json-schema-tools copied to clipboard
json-schema-ref-loader can't handle circular references
A simple JSON schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"node": {
"title": "a node",
"type": "object",
"properties": {
"children": {
"type": "array",
"items": {
"$ref": "#/definitions/node"
}
}
}
}
}
}
causes json-schema-loader to fail with the following error:
ERROR in ../src/schema/node.json
Module build failed: TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at Object.handleResolveSuccess (/Users/fabian/projects/node-lib-spec/schema-doc/node_modules/json-schema-loader/lib/loader.js:19:21)
at <anonymous>
I can fix it locally if I apply the change proposed in https://github.com/cloudflare/json-schema-loader/pull/3
@FabianFrank a PR would be most welcome! You will need to dig into @cloudflare/json-schema-transform as it wraps up the json-schema-ref-loader with some functionality to support a broader range of file formats. Let me know if you don't see what I mean.
Oh and if you fix this please update the README in the json-schema-ref-loader workspace as it currently notes the cyclic references limitation.
@handrews Do you know if a solution has been worked on since last update in April 2018? The project I'm working on uses getCollapseAllOfCallback for collapsing the allOf, but apparently, it won't work for circular reference although the RefParser was able to handle circular reference.
@5amfung I'm afraid I left the company not too long after my last comment above. @zackproser any idea if there's any active work here?