You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
When using models with circular references, the generated JSON-schema (using model_json_schema) has an unexpected output (at least for me). Instead of defining the model on the root there will be an allOf present with a reference to the model in $defs. I believe it was solved this way to avoid redundance since the model must be present in $defs in order to correctly model the circular reference. However, I think this redundance sometimes can be helpful. Currently I'm modifying the result schema by myself to achieve this. I think an option for this on model_json_schema would be best. Or at least a short description in the documentation.
Thanks for your question - indeed, we simplify the schema in this way to represent the circular reference without unneeded redundancy.
Modification of the schema in the way that you're requesting seems relatively unique, so I think these changes belong in user code for now. That being said, if requests such as this one get significant traction, we could reconsider adding increased support (or at least examples for how to achieve such schema to the docs).
Closing this as not planned, based on that analysis, for now.
Initial Checks
Description
When using models with circular references, the generated JSON-schema (using
model_json_schema
) has an unexpected output (at least for me). Instead of defining the model on the root there will be anallOf
present with a reference to the model in$defs
. I believe it was solved this way to avoid redundance since the model must be present in$defs
in order to correctly model the circular reference. However, I think this redundance sometimes can be helpful. Currently I'm modifying the result schema by myself to achieve this. I think an option for this onmodel_json_schema
would be best. Or at least a short description in the documentation.Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: