这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@mt35-rs
Copy link
Contributor

@mt35-rs mt35-rs commented Nov 30, 2022

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 $ref rather 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 $ref I added was something like ./schemas/Foo, when it gets generated by the schemas endpoint it is ./schemas/Foo.json which is not good. Specifically, I'm thinking about cases where we might want to put in a $ref that is something like #/definitions/Foo. In that case, no .json is 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 $ref that looks something like ./schemas/Struct[parameter].json. The /schemas endpoint 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.

This is because downstream processing takes care of replacing these fragments
with resolvable URLs.
This isn't needed now that we deal with recursion in a clean way using refs.  Also,
I think there was a bug here in this detection anyway.
Copy link
Owner

@danielgtaylor danielgtaylor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks reasonable to me, thank you!

@danielgtaylor danielgtaylor merged commit 4676b6d into danielgtaylor:main Dec 2, 2022
@mtiller mtiller mentioned this pull request Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants