Optional fields and nullability - OpenAPI spec #3122
bunny-therapist
started this conversation in
Potential Issues
Replies: 1 comment 6 replies
-
You'll simply have to remove the default value. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The request/response bodies in my application are defined via pydantic models, and they have some optional fields, i.e., fields which do not have to appear in the body. The models define these as
Optional[X] = None
(whereX
is some type). The resulting OpenAPI specification describes these parameters as not required (there is no "required" text below the parameter name), and states their types as "null or X".However, my actual intention is for these fields to either be present, with type X, or completely absent. So the field should be of type X (not "null or X"), just not required. I can't find any way to define this behavior. I believe OpenAPI itself makes a distinction between nullability and optional fields (
nullable
is a separate field fromrequired
), so I feel like there should be a way to do it. Is there? Should there be? If not, is it a shortcoming of Litestar or of pydantic?Beta Was this translation helpful? Give feedback.
All reactions