datamodel-code-generator
datamodel-code-generator copied to clipboard
nullable array items are not defined as Optional, despite using --strict-nullable
Describe the bug
Items in an array are not generated as Optional, despite adding the nullable: true property.
To Reproduce
Example schema:
# test.yml
properties:
list1:
type: array
items:
type: string
nullable: true
required:
- list1
Used commandline:
$ datamodel-codegen --input test.yml --output model.py --strict-nullable
This generates a datamodel in which the list items are not nullable:
class Model(BaseModel):
list1: List[str]
Expected behavior I would expect Optional array items to be generated:
class Model(BaseModel):
list1: List[Optional[str]]
Version:
- OS: iOS 14.2.1
- Python version: 3.8.10
- datamodel-code-generator version: 0.25.2