quart-schema
quart-schema copied to clipboard
support response_model_exclude_unset
Apologies if I missed it, but is there a way to exclude unset parameters from the generated response? Similar to FASTAPI's response_model_exclude_unset parameter? As far as I can tell, it sets the exclude_unset
parameter in pydantic's model_dump
.
For example, I have an API endpoint that returns content and an optional warning:
@dataclass
class ListResponse:
content: list[str]
warning: Optional[str]
I am currently getting errors when the warning is not set, as it is looking for the warning field. Especially in responses I do not find this intuitive: I specified it's an optional field, so why complain that it's missing? I could solve this by setting a default value, e.g.
@dataclass
class ListResponse:
content: list[str]
warning: Optional[str]=None
But then all responses will include an empty warning field, whereas I'd prefer the warning field to be absent entirely.