Skip to content

Validation for Empty Objects on Object Level #42

@julian-r

Description

@julian-r

ATM the validation of empty object is only working in dict form.

Example:

 RootModel(
        field_a="a", list_items=[ListItem(), ListItem(), ListItem()]
    ).dict() == {"field_a": "a"}

does not raise an validation error. But it actually should.

RootModel(**{"field_a": "a", "list_items": [{}, {}, {}]})

Does.

The problem is in resource header strip_empty_items since it only takes care about the dict representation of the model, which is not executed in case of the construction via Objects. A similar functionality needs to be implemented on a Pydantic object level without the pre parameter in the validator. This should then cover the json variant as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggenerator-pydanticCode generator for python pydantic

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions