default=[] and default_factory=list marks field as Optional
in OpenAPI documentation
#4577
-
Hi, When I have a model like this: class X(BaseModel):
list_item: list[str] = Field(default=[]) The list will always be there, it won't be The solution is to do this: class X(BaseModel):
list_item: list[str] = Field(default=...) but that also forces me to always create Is OpenAPI documentation generated without using type hints, since this don't work? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I guess a decent workaround is to do this: class X(BaseModel):
list_item: list[str] = Field(default=[])
class Config:
schema_extra = {
'required': ['list_item']
} Even though the behavior seems a bit counterintuitive to me. |
Beta Was this translation helpful? Give feedback.
-
Moved to issue and replied there, see #4697. |
Beta Was this translation helpful? Give feedback.
Moved to issue and replied there, see #4697.