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):
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):