json-schema-merge-allof
json-schema-merge-allof copied to clipboard
Doesn't work with schemas that have cyclical references
Some schemas have cyclical references. For example, a definition in the schema tree references a parent or ancestor
For an example in the wild see the bitbucket API swagger definition. https://api.bitbucket.org/swagger.json. The schema definition for "repository" in the definitions section has a reference to a parent repository.
Trying to use json-schema-merge-allof on this schema will cause Exception: Maximum call stack size exceeded
because of infinite recursion.
For now, I can set deep: false but it would be nice if the library could detect that it is in an infinite recursion or alternatively, I could set a depth that would set the maximum recursions on a schema.
Yeah I could maybe support that in the future.
I assume you use something like json-schema-ref-parser parser to dereference the schema? If you use the bundle
function instead of dereference
it will create a schema without circular references, but still dereference all into one schema.
Hi, I had the same problem with cyclical references, so I wrote my own implementation, which solves this problem. You can try it: https://github.com/udamir/allof-merge