feat: avoids infinite recursion #77
Merged
+27
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I'm submitting this pull request in response to issue #75.
This keeps track (during recursion) of what (
struct) types have already been defined. If it encounters an already defined schema, it simply replaces it with an$refrather than elaborating the schema again (and again, and again).This isn't perfect. It makes some assumptions about the schema name.
Note, even though the
$refI added was something like./schemas/Foo, when it gets generated by the schemas endpoint it is./schemas/Foo.jsonwhich is not good. Specifically, I'm thinking about cases where we might want to put in a$refthat is something like#/definitions/Foo. In that case, no.jsonis required (or desirable). So you might want to consider revisiting the logic that appends to the$refs.The other problem here is one that I mentioned in #74 which is that if any of these recursive schemas are generic, then you get a
$refthat looks something like./schemas/Struct[parameter].json. The/schemasendpoint cannot handles these. So while the schema generation part now works (no more crashes due to infinite recursion), it will almost certainly run into trouble if any client were to actually follow these$refs.Please let me know if any others concerns you have with this PR.