Skip to content

Deserialise models without schema fix #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2020
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 == {}