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
TypeAdapter.json_schema drops description
from Annotated Fields when self.type is a function
#9404
Comments
description
from Annotated Fields description
from Annotated Fields when self.type is a function
Hi @cisaacstern, Thanks for your kind words. We really appreciate the in-depth description and MRE :). Thanks for reporting this - definitely looks like a bug, and is something we should fix. Are you interested in opening a PR to address this issue? |
@sydney-runkle, thanks for your reply! Yes, I would be happy to make a PR. I will ping back here when I have one for review and/or if I need further guidance. 🙏 |
Fantastic! Sorry for the delayed response last week, was out for vacation. |
I thank you as well. I have put your workaround to good use. |
Working on this now. It's quite messy, lots of core schema issues for parameters. Should have a fix done by the end of the week. |
Thanks @sydney-runkle! It would be quite some time before I have enough bandwidth to work on this, so very happy to know you are working on it! TYSM! |
Initial Checks
Description
I was very happy to learn about
TypeAdapter
via reading #7133.In experimenting with generation of JSON Schema from plain python functions, I found that the
description
attribute of an Annotated Field is dropped from the default generated JSON Schema if the type passed toTypeAdapter
is a plain function.If the type passed to
TypeAdapter
is a type alias (the Annotated Field itself) or aBaseModel
using that type, thedescription
attribute is preserved.The MRE provided below demonstrates this issue and a workaround using a subclass of
GenerateJsonSchema
.Is it reasonable to expect that the default schema generator would produce the same JSON for the same Annotated Field used in these three different settings? If so, would the team be open to a PR upstreaming the behavior of this workaround into the default?
Thank you all very much, Pydantic is truly remarkable.
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: