-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recursive schema definitions result in infinite recursion #8
Comments
I like your suggestion! Actually, we wanted to do anchor links for a while and never got around to it, so that would be very nice. Let me know if you intend to work on a PR, I may do something on my side otherwise. |
Ok cool! I don't have a PR planned as of now. I'll let you know if I circle back to it at some point |
@dblanchette @sw23 this is a very nice project. I am eager to start using it. However almost all the json schemas that I write have recursions, so this issue blocks me from using it. Just wondering if you are working on this or if there is some plan for it. |
Hi @mauvilsa, I was able to fix part of the issue. From the schema: {
"$id": "https://example.com/person.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"person": {
"$ref": "#/definitions/person"
}
},
"definitions": {
"person": {
"type": "object",
"description": "A human being",
"properties": {
"children": {
"type": "array",
"description": "The children they had",
"items": {
"$ref": "#/definitions/person"
}
}
}
}
}
} However, this does not work for all schema, here is what I get for another one: The other schema: {
"$id": "https://example.com/person.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"a_list_of_people": {
"type": "array",
"description": "A list of people",
"items": {
"$ref": "#/definitions/person"
}
}
},
"definitions": {
"person": {
"type": "object",
"description": "A human being",
"properties": {
"children": {
"type": "array",
"description": "The children they had",
"items": {
"$ref": "#/definitions/person"
}
}
}
}
}
} Not everything has anchor links currently, only the properties and "tabs" ( I realize that mentioning the path of the property in the schema is of little help, so I will keep looking for a solution. I can release this partial solution if you think it has some value. |
Hi @dblanchette. This partial fix is in master or a branch? No need to release a partial solution, I can try with my schemas cloning the repo. Better to release when there is a more general solution. |
@mauvilsa You can see PR #26 for a more complete fix. Both examples from my last comment now works and clicking on the anchor link to the referenced section will make it flash so that users may see what exactly is being referenced. I invite you to try it out and I would be glad to have your comments on it. |
@dblanchette I have tried it with one of the schemas I am currently working on. Running You can find the schema that I tested on at https://github.com/omni-us/narchi/blob/master/schema/narchi_schema.json and also the generated html at https://omni-us.github.io/narchi/schema.html. The problem is that |
@mauvilsa Thanks for the real life example, it really helps me. I found some issues:
I fixed those and pushed to the PR branch (#26). However, it is not complete, tests will need to be adjusted. Also, we do not support the |
Released in version 0.10! |
Currently if you have a schema with a recursive definition, the code will spin on the recursion until hitting the max recursion limit. Here's an example of a recursive schema definition:
I worked around this by hacking the code to stop resolving references after a certain depth, which is a fairly simple solution. I think a better solution would be to catch when schemas reference a parent element, and to create an anchor link to the parent. That would prevent duplicate content as well.
Any thoughts?
The text was updated successfully, but these errors were encountered: