-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add support for JSON Schema with circular references in Python 3.7 #572
Add support for JSON Schema with circular references in Python 3.7 #572
Conversation
Codecov Report
@@ Coverage Diff @@
## master #572 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 2498 2508 +10
Branches 499 501 +2
=====================================
+ Hits 2498 2508 +10 |
There's something strange happening to GitHub. The tests finished a while ago, but they still show up as "running". The same for Travis and for the tests in Netlify. And the coverage was raise again, removing the partial, but the comment still hasn't been updated. |
@@ -662,6 +691,7 @@ def field_singleton_schema( # noqa: C901 (ignore complexity) | |||
model_name_map: Dict[Type['BaseModel'], str], | |||
schema_overrides: bool = False, | |||
ref_prefix: Optional[str] = None, | |||
known_models: Set[Type['BaseModel']], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this function is MASSIVE is there anything we can do to simplify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check what I can do...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's not possible or too difficult, don't worry. Maybe better to do in a separate PR anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I agree it's big. But I don't really know what to put outside, I don't see much code repetition as it handles several different cases.
Maybe the last section that checks if it's a model, under if issubclass(field_type, pydantic.BaseModel):
could be in a function...
But it would require several parameters, would have to modify some of them (which is a bit difficult to debug/refactor later) and would require an extra if
to check if it returned a value (to return it) or not, so I'm not sure.
Do you want me to put it outside? Or later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do it (or not do it) later.
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
awesome. Thank you. |
Great! Thanks 🎉 |
Change Summary
Add JSON Schema generation support for models with circular references, including self-referencing.
Related issue number
This fixes #531, the comment in #524 (comment).
I think parts of it might move in the direction of #478 too.
Checklist
HISTORY.rst
has been updated#<number>
@<whomever>