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
Pydantic computed field example values #7864
Comments
Hi @rsaleev, Thanks for your feedback. Could you provide an example MRE code snippet so that we can better understand what you're asking for? Thanks 👍 |
No examples available for OpenAPI, only attr will be shown with field type
Examples will be shown in rendered OpenAPI docs |
Thanks for the response. This seems like a reasonable feature request - I think we could also include |
Started looking into this issue without hard commitment (Also leave the comment as a marker, so I can find the page again). |
PR: #8013 |
I see we merged #8013 but I do want to point out that from typing import Annotated
from pydantic import BaseModel, Field, computed_field
class Model(BaseModel):
a: int
b: int
@computed_field
@property
def c(self) -> Annotated[int, Field(description='The sum of a and b', examples=[3, 5])]:
return self.a + self.b
print(Model.model_json_schema(mode='serialization')['properties']['c'])
# {'description': 'The sum of a and b', 'examples': [3, 5], 'readOnly': True, 'title': 'C', 'type': 'integer'} This avoids having to duplicate the entirety of |
Initial Checks
Description
Maybe my approach is not right but I use
computed_field
wrapper for injecting ORM values in root model and it will be for sure a cool feature to have examples like forField
, less code and integration with FastAPI/OpenAPIAffected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: