I am currently creating an enpoint using FastAPI and Pydantic. I have following Pydantic model that has multiple None values. Here is some part of the model:
class MyModel(BaseModel):
comment: Optional[str] = Field(None, description='Comment')
description: Optional[str] = Field(
None, description='Description'
)
So far so good. The problem is when I actually use this model as a body for the enpoint and open the docs page of my service and check the endpoint in the swagger ui, the values for the fields that should be seen as null are seen as "string" and not as null. Like this:
"comment": "string",
"description": "string"
This is a problem for me because the end user will use the swagger ui and if the fields comment and description are not deleted from the payload they will get a default value "string", and I want it to get default value of null. Of course, I can implement some logic that the "string" actually means None in the enpoint, but is there a way to display the attributes like this in the swagger ui from the start:
"comment": null,
"description": null
Thanks in advance!