skalarsystems / fhirzeug

A Python FHIR specification parser and class generator
Apache License 2.0
17 stars 1 forks source link

Validation for Empty Objects on Object Level #42

Open julian-r opened 4 years ago

julian-r commented 4 years ago

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.

julian-r commented 4 years ago

the tests should be renamed as well. Thanks @trojanowski