You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
We'd need to override on the Schema model itself, since it is the base class of a NinjaResponseSchema class that wraps MySchema when rendering the swagger UI.
Describe the bug
computed_field
is missing in openapi spec.I have defined a schema to be used for responses like this:
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 handlemode="serialization"
.I decided not to investigate it farther and opened the issue.
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: