Open
Description
Describe the bug
computed_field
is missing in openapi spec.
I have defined a schema to be used for responses like this:
class MySchema(Schema):
id: int
slug: str
@computed_field
def name(self) -> str:
return f"{self.id}-{self.slug}"
def model_json_schema(self, *args, **kwargs):
# This is a workaround for the issue with the generated schema to include computed_field
return super().model_json_schema(*args, mode="serialization", **kwargs)
The overwritten model_json_schema
is an attempt to fix the issue according to pydantic issue here.
Anyway the fix doesn't work, looks like NinjaGenerateJsonSchema
doesn't handle mode="serialization"
.
I decided not to investigate it farther and opened the issue.
Versions (please complete the following information):
- Python version: Python 3.10.3
- Django version: 3.2.13
- Django-Ninja version: 1.1.0
- Pydantic version: 2.7.4
Metadata
Metadata
Assignees
Labels
No labels