Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions openapi_core/schema/media_types/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def deserialize(self, value):
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:
Expand Down
6 changes: 3 additions & 3 deletions openapi_core/schema/parameters/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def cast(self, value):
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:
Expand Down
12 changes: 11 additions & 1 deletion tests/unit/schema/test_media_types.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytest

from openapi_core.schema.media_types.exceptions import InvalidMediaTypeValue
from openapi_core.schema.media_types.models import MediaType


Expand All @@ -7,6 +10,13 @@ def test_empty(self):
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 == {}