null values are discarded from OpenAPI examples #8401
Replies: 2 comments
-
Over a year later, coming across my own issue... Which has been converted into a discussion?! With Pydantic 2.x, there's a clear differentiation between required and optional. This causes my OpenAPI examples to be incorrect, because null values are omitted for required fields. |
Beta Was this translation helpful? Give feedback.
-
Bump. I'm experiencing the same and it's a headache. A required parameter with null as an acceptable value is not the same as an optional parameter. This should be rectified, given the obvious interest on this discussion and the issue that spawned it. Or at the very least, implement a mechanism whereby developers can toggle whether or not display null parameters via the examples. |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Taken from https://fastapi.tiangolo.com/advanced/additional-responses/
Description
example
orexamples
)None
The code above outputs:
As you can see, the
absent
example is absent.Operating System
Linux
Operating System Details
No response
FastAPI Version
0.73.0
Python Version
3.8.9
Additional Context
openapi.utils.get_openapi
has this line:exclude_none
could cause the issue.When setting it to True, OpenAPI generation fails with the following error:
Beta Was this translation helpful? Give feedback.
All reactions