json-schema-tools icon indicating copy to clipboard operation
json-schema-tools copied to clipboard

json-schema-ref-loader can't handle circular references

Open FabianFrank opened this issue 7 years ago • 5 comments

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>

FabianFrank avatar Apr 24 '18 22:04 FabianFrank

I can fix it locally if I apply the change proposed in https://github.com/cloudflare/json-schema-loader/pull/3

FabianFrank avatar Apr 24 '18 22:04 FabianFrank

@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.

handrews avatar Apr 25 '18 01:04 handrews

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 avatar Apr 25 '18 01:04 handrews

@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 avatar Feb 01 '19 20:02 5amfung

@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?

handrews avatar Feb 02 '19 18:02 handrews