mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-22 03:00:10 +00:00
Deserialize models without schema
This commit is contained in:
parent
cb54400136
commit
475076a2a2
3 changed files with 17 additions and 7 deletions
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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 == {}
|
||||
|
|
Loading…
Reference in a new issue