Fix GenerateJsonSchema.generate_definitions
signature
#6436
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.
This massively improves the
GenerateJsonSchema.generate_definitions
API — discovered the need for this while working with @tiangolo through FastAPI test failures with pydantic v2.In particular, prior to this change, the first item returned by the
GenerateJsonSchema.generate_definitions
would only include a mapping to schemas that were "pure" definition schemas. Now, it will include every set of inputs as a mapped output.In particular, we were able to make this usable from FastAPI for the purpose of exposing the
mode='serialization'
capability, fixing some bugs with the FastAPI generation, and significantly reduce the overhead of generating JSON schema — it previously needed to be computed twice because the map returned by the function didn't have all (or even most) of the data necessary; now it does. (This is used on themain-pv2-serialization-schemas
.)If there are any objections to making this change to the
generate_definitions
method in pydantic, I would suggest we add a new method with a new name that does exactly this. However, considering how much more useful this method is and the fact that we currently viewGenerateJsonSchema
as "unstable", I would be in favor of just making this change to that method's signature. Open to disagreement on this.