mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 19:19:23 +00:00
Unmarshalling nullable objects
This commit is contained in:
parent
1270d5a6b9
commit
7307794656
2 changed files with 21 additions and 2 deletions
|
@ -157,9 +157,16 @@ class ObjectUnmarshaller(ComplexUnmarshaller):
|
||||||
def model_factory(self):
|
def model_factory(self):
|
||||||
return ModelFactory()
|
return ModelFactory()
|
||||||
|
|
||||||
def __call__(self, value=NoValue):
|
def unmarshal(self, value):
|
||||||
value = super(ObjectUnmarshaller, self).__call__(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:
|
if self.schema.one_of:
|
||||||
properties = None
|
properties = None
|
||||||
for one_of_schema in self.schema.one_of:
|
for one_of_schema in self.schema.one_of:
|
||||||
|
|
|
@ -408,6 +408,18 @@ class TestSchemaUnmarshallerCall(object):
|
||||||
|
|
||||||
assert result == 1.2
|
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):
|
def test_schema_any_one_of(self, unmarshaller_factory):
|
||||||
schema = Schema(one_of=[
|
schema = Schema(one_of=[
|
||||||
Schema('string'),
|
Schema('string'),
|
||||||
|
|
Loading…
Reference in a new issue