json-schema-merge-allof icon indicating copy to clipboard operation
json-schema-merge-allof copied to clipboard

Doesn't work with schemas that have cyclical references

Open ryanackley opened this issue 2 years ago • 2 comments

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.

ryanackley avatar Nov 10 '22 11:11 ryanackley

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.

mokkabonna avatar Feb 25 '23 22:02 mokkabonna

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

udamir avatar Jun 19 '23 18:06 udamir