Deserialize models without schema

This commit is contained in:
Artur Maciag 2020-02-03 09:15:37 +00:00
parent cb54400136
commit 475076a2a2
3 changed files with 17 additions and 7 deletions

View file

@ -32,14 +32,14 @@ class MediaType(object):
return deserializer(value)
def cast(self, value):
if not self.schema:
return value
try:
deserialized = self.deserialize(value)
except ValueError as exc:
raise InvalidMediaTypeValue(exc)
if not self.schema:
return deserialized
try:
return self.schema.cast(deserialized)
except CastError as exc:

View file

@ -99,14 +99,14 @@ class Parameter(object):
not self.allow_empty_value):
raise EmptyParameterValue(self.name)
if not self.schema:
return value
try:
deserialized = self.deserialize(value)
except (ValueError, AttributeError) as exc:
raise InvalidParameterValue(self.name, exc)
if not self.schema:
return deserialized
try:
return self.schema.cast(deserialized)
except CastError as exc:

View file

@ -1,3 +1,6 @@
import pytest
from openapi_core.schema.media_types.exceptions import InvalidMediaTypeValue
from openapi_core.schema.media_types.models import MediaType
@ -7,6 +10,13 @@ class TestMediaTypeCast(object):
media_type = MediaType('application/json')
value = ''
with pytest.raises(InvalidMediaTypeValue):
media_type.cast(value)
def test_no_schema_deserialised(self):
media_type = MediaType('application/json')
value = "{}"
result = media_type.cast(value)
assert result == value
assert result == {}