Skip to content

Get rid of unmarshal in schema #189

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
16 changes: 0 additions & 16 deletions openapi_core/schema/schemas/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

from openapi_core.schema.schemas.enums import SchemaType
from openapi_core.schema.schemas.types import NoValue
from openapi_core.unmarshalling.schemas.exceptions import (
UnmarshalValueError,
)

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -104,16 +101,3 @@ def cast(self, value):
return caster(value)
except (ValueError, TypeError):
raise CastError(value, self.type)

def unmarshal(self, value, resolver=None, custom_formatters=None):
"""Unmarshal parameter from the value."""
from openapi_core.unmarshalling.schemas.factories import (
SchemaUnmarshallersFactory,
)
unmarshallers_factory = SchemaUnmarshallersFactory(
resolver, custom_formatters)
unmarshaller = unmarshallers_factory.create(self)
try:
return unmarshaller(value)
except ValueError as exc:
raise UnmarshalValueError(value, self.type, exc)
16 changes: 0 additions & 16 deletions openapi_core/unmarshalling/schemas/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@ class UnmarshallerError(UnmarshalError):
pass


@attr.s(hash=True)
class UnmarshalValueError(UnmarshalError):
"""Failed to unmarshal value to type"""
value = attr.ib()
type = attr.ib()
original_exception = attr.ib(default=None)

def __str__(self):
return (
"Failed to unmarshal value {value} to type {type}: {exception}"
).format(
value=self.value, type=self.type,
exception=self.original_exception,
)


@attr.s(hash=True)
class InvalidSchemaValue(ValidateError):
value = attr.ib()
Expand Down
11 changes: 7 additions & 4 deletions openapi_core/validation/request/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ def _unmarshal(self, param_or_media_type, value):
if not param_or_media_type.schema:
return value

return param_or_media_type.schema.unmarshal(
value,
resolver=self.spec._resolver,
custom_formatters=self.custom_formatters,
from openapi_core.unmarshalling.schemas.factories import (
SchemaUnmarshallersFactory,
)
unmarshallers_factory = SchemaUnmarshallersFactory(
self.spec._resolver, self.custom_formatters)
unmarshaller = unmarshallers_factory.create(
param_or_media_type.schema)
return unmarshaller(value)
11 changes: 7 additions & 4 deletions openapi_core/validation/response/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ def _unmarshal(self, param_or_media_type, value):
if not param_or_media_type.schema:
return value

return param_or_media_type.schema.unmarshal(
value,
resolver=self.spec._resolver,
custom_formatters=self.custom_formatters,
from openapi_core.unmarshalling.schemas.factories import (
SchemaUnmarshallersFactory,
)
unmarshallers_factory = SchemaUnmarshallersFactory(
self.spec._resolver, self.custom_formatters)
unmarshaller = unmarshallers_factory.create(
param_or_media_type.schema)
return unmarshaller(value)
Loading