Skip to content

Commit 7307794

Browse files
committed
Unmarshalling nullable objects
1 parent 1270d5a commit 7307794

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

openapi_core/unmarshalling/schemas/unmarshallers.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,16 @@ class ObjectUnmarshaller(ComplexUnmarshaller):
157157
def model_factory(self):
158158
return ModelFactory()
159159

160-
def __call__(self, value=NoValue):
161-
value = super(ObjectUnmarshaller, self).__call__(value)
160+
def unmarshal(self, value):
161+
try:
162+
value = self.formatter.unmarshal(value)
163+
except ValueError as exc:
164+
raise InvalidSchemaFormatValue(
165+
value, self.schema.format, exc)
166+
else:
167+
return self._unmarshal_object(value)
162168

169+
def _unmarshal_object(self, value=NoValue):
163170
if self.schema.one_of:
164171
properties = None
165172
for one_of_schema in self.schema.one_of:

tests/unit/unmarshalling/test_unmarshal.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,18 @@ def test_number_format_double(self, unmarshaller_factory):
408408

409409
assert result == 1.2
410410

411+
def test_object_nullable(self, unmarshaller_factory):
412+
schema = Schema(
413+
'object',
414+
properties={
415+
'foo': Schema('object', nullable=True),
416+
},
417+
)
418+
value = {'foo': None}
419+
result = unmarshaller_factory(schema)(value)
420+
421+
assert result == {'foo': None}
422+
411423
def test_schema_any_one_of(self, unmarshaller_factory):
412424
schema = Schema(one_of=[
413425
Schema('string'),

0 commit comments

Comments
 (0)