Skip to content
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

Fix GenerateJsonSchema.generate_definitions signature #6436

Merged
merged 1 commit into from Jul 5, 2023

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Jul 4, 2023

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 the main-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 view GenerateJsonSchema as "unstable", I would be in favor of just making this change to that method's signature. Open to disagreement on this.

@cloudflare-pages
Copy link

cloudflare-pages bot commented Jul 4, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: eeb9fea
Status: ✅  Deploy successful!
Preview URL: https://307b470c.pydantic-docs2.pages.dev
Branch Preview URL: https://fix-generate-definitions.pydantic-docs2.pages.dev

View logs

Copy link
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

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

Yessss! Thanks 🚀

@samuelcolvin samuelcolvin merged commit 4b2ea6f into main Jul 5, 2023
50 checks passed
@samuelcolvin samuelcolvin deleted the fix-generate-definitions branch July 5, 2023 09:49
@samuelcolvin
Copy link
Member

amazing 🚀 .

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.

None yet

4 participants