Skip to content

nullable array items are not defined as Optional, despite using --strict-nullable #1815

@pfaizian

Description

@pfaizian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions