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

Field() supports json_schema_extra for Pydantic v2 #1035

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KimigaiiWuyi
Copy link

@KimigaiiWuyi KimigaiiWuyi commented Jul 26, 2024

According to what this link mentions,

PydanticV1's Field class supported passing arbitrary keyword arguments to the JSON schema. In SQLModel counterpart, it was supported by passing schema_extra (see this).

PydanticV2 still supports passing extra things to the JSON schema but in a slightly different way. One has to pass a dictionary in the json_schema_extra argument (see this).

Field no longer supports arbitrary keyword arguments to be added to the JSON schema. Instead, any extra data you want to add to the JSON schema should be passed as a dictionary to the json_schema_extra keyword argument.

So I modified the Field's parameters to be compatible and consistent with the Pydantic v2 parameters, and for backward compatibility, I didn't remove the schema_extra field, which is logically compatible with both the schema_extra and json_schema_extra passes, and schema_extra should be deprecated at some point in the future. field at some point in the future, but for now schema_extra should be retained.

This Pull Reqeust is easy and simple, and easy to verify.

@Kaplas85
Copy link

Any news about this PR?

@ndeybach
Copy link

ndeybach commented Dec 26, 2024

Any possibility of a merge @tiangolo ? I would also be interested in this support being added / long term.

@paulomtts
Copy link

Please merge this.

@svlandeg svlandeg changed the title 🎨 Field() supports json_schema_extra for Pydantic v2 Field() supports json_schema_extra for Pydantic v2 Feb 24, 2025
@svlandeg svlandeg added the feature New feature or request label Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants