Closed Danferno closed 3 months ago
Yep, supported via abf72c15523ca1dfb2e926a3f94c74f76eeaf1b2.
See also https://github.com/jcrist/msgspec/issues/633 for msgspec equivalent support.
Is there a way to already use the version where this is patched? Unless I'm mistaken the pypi version doesn't include it yet
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'smodel_dump
.For example, I have an API endpoint that returns content and an optional warning:
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.
But then all responses will include an empty warning field, whereas I'd prefer the warning field to be absent entirely.