diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index b60f9c31..015edff8 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -144,7 +144,8 @@ def items_unmarshaller(self): def __call__(self, value=NoValue): value = super(ArrayUnmarshaller, self).__call__(value) - + if value is None and self.schema.nullable: + return None return list(map(self.items_unmarshaller, value)) diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index 484fa685..b97b7f81 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -352,6 +352,27 @@ def test_array_valid(self, unmarshaller_factory): assert result == value + def test_array_null(self, unmarshaller_factory): + schema = Schema( + 'array', + items=Schema('integer'), + ) + value = None + + with pytest.raises(TypeError): + unmarshaller_factory(schema)(value) + + def test_array_nullable(self, unmarshaller_factory): + schema = Schema( + 'array', + items=Schema('integer'), + nullable=True, + ) + value = None + result = unmarshaller_factory(schema)(value) + + assert result is None + def test_array_of_string_string_invalid(self, unmarshaller_factory): schema = Schema('array', items=Schema('string')) value = '123'