mokkabonna / json-schema-merge-allof

Simplify your schema by combining allOf
97 stars 23 forks source link

Doesn't work with schemas that have cyclical references #36

Open ryanackley opened 1 year ago

ryanackley commented 1 year ago

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.

mokkabonna commented 1 year ago

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.

udamir commented 1 year ago

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