From 6600f0c3e1ea9448071642ca73f8f0483298ac83 Mon Sep 17 00:00:00 2001 From: Justin Godesky Date: Tue, 12 Jan 2021 20:14:46 -0500 Subject: [PATCH 1/2] ArrayUnmarshaller return None on nullable --- openapi_core/unmarshalling/schemas/unmarshallers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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)) From 22a2771fa054fa7b03ea59389e3d88744e73b409 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Mon, 1 Feb 2021 20:47:37 +0000 Subject: [PATCH 2/2] add test for ArrayUnmarshaller return nullable --- tests/unit/unmarshalling/test_unmarshal.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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'