From 7307794656106323b1f46cebd7525fcb265f5f28 Mon Sep 17 00:00:00 2001 From: p1c2u Date: Sun, 12 Apr 2020 14:59:22 +0100 Subject: [PATCH] Unmarshalling nullable objects --- openapi_core/unmarshalling/schemas/unmarshallers.py | 11 +++++++++-- tests/unit/unmarshalling/test_unmarshal.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/openapi_core/unmarshalling/schemas/unmarshallers.py b/openapi_core/unmarshalling/schemas/unmarshallers.py index 5f924d4..25b1aff 100644 --- a/openapi_core/unmarshalling/schemas/unmarshallers.py +++ b/openapi_core/unmarshalling/schemas/unmarshallers.py @@ -157,9 +157,16 @@ class ObjectUnmarshaller(ComplexUnmarshaller): def model_factory(self): return ModelFactory() - def __call__(self, value=NoValue): - value = super(ObjectUnmarshaller, self).__call__(value) + def unmarshal(self, value): + try: + value = self.formatter.unmarshal(value) + except ValueError as exc: + raise InvalidSchemaFormatValue( + value, self.schema.format, exc) + else: + return self._unmarshal_object(value) + def _unmarshal_object(self, value=NoValue): if self.schema.one_of: properties = None for one_of_schema in self.schema.one_of: diff --git a/tests/unit/unmarshalling/test_unmarshal.py b/tests/unit/unmarshalling/test_unmarshal.py index e8c7609..8c58809 100644 --- a/tests/unit/unmarshalling/test_unmarshal.py +++ b/tests/unit/unmarshalling/test_unmarshal.py @@ -408,6 +408,18 @@ class TestSchemaUnmarshallerCall(object): assert result == 1.2 + def test_object_nullable(self, unmarshaller_factory): + schema = Schema( + 'object', + properties={ + 'foo': Schema('object', nullable=True), + }, + ) + value = {'foo': None} + result = unmarshaller_factory(schema)(value) + + assert result == {'foo': None} + def test_schema_any_one_of(self, unmarshaller_factory): schema = Schema(one_of=[ Schema('string'),