From 5ba7b6198f8e8a7c05348c547e8025dfde4b54cc Mon Sep 17 00:00:00 2001 From: Jonas Stendahl Date: Tue, 4 Oct 2022 22:25:29 +0200 Subject: [PATCH 1/2] Add failing test for lists as additional properties --- tests/unit/unmarshalling/test_unmarshal.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index cc332f1b..8dbca416 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -816,3 +816,16 @@ def test_write_only_properties_invalid(self, unmarshaller_factory): unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)( {"id": 10} ) + + def test_additional_properties_list(self, unmarshaller_factory): + schema = { + "type": "object" + } + spec = Spec.from_dict(schema) + + result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)( + {"user_ids": [1, 2, 3, 4]} + ) + + assert is_dataclass(result) + assert result.user_ids == [1, 2, 3, 4] From 9c3e43000d0c51d0f5be712726333ef44a51bb26 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Wed, 5 Oct 2022 08:28:04 +0100 Subject: [PATCH 2/2] lists as additional properties fix --- openapi_core/unmarshalling/schemas/unmarshallers.py | 4 +++- tests/unit/unmarshalling/test_unmarshal.py | 4 +--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index b057aa01..872d74b0 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -181,7 +181,9 @@ class ArrayUnmarshaller(ComplexUnmarshaller): @property def items_unmarshaller(self) -> "BaseSchemaUnmarshaller": - return self.unmarshallers_factory.create(self.schema / "items") + # sometimes we don't have any schema i.e. free-form objects + items_schema = self.schema.get("items", Spec.from_dict({})) + return self.unmarshallers_factory.create(items_schema) def __call__(self, value: Any) -> Optional[List[Any]]: value = super().__call__(value) diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index 8dbca416..0a9a545a 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -818,9 +818,7 @@ def test_write_only_properties_invalid(self, unmarshaller_factory): ) def test_additional_properties_list(self, unmarshaller_factory): - schema = { - "type": "object" - } + schema = {"type": "object"} spec = Spec.from_dict(schema) result = unmarshaller_factory(spec, context=UnmarshalContext.RESPONSE)(