Skip to content

Commit cb54400

Browse files
authored
Merge pull request #189 from p1c2u/refactor/get-rid-of-unmarshal-in-schema
Get rid of unmarshal in schema
2 parents b003ccc + 61fb830 commit cb54400

File tree

6 files changed

+341
-368
lines changed

6 files changed

+341
-368
lines changed

openapi_core/schema/schemas/models.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
from openapi_core.schema.schemas.enums import SchemaType
77
from openapi_core.schema.schemas.types import NoValue
8-
from openapi_core.unmarshalling.schemas.exceptions import (
9-
UnmarshalValueError,
10-
)
118

129
log = logging.getLogger(__name__)
1310

@@ -104,16 +101,3 @@ def cast(self, value):
104101
return caster(value)
105102
except (ValueError, TypeError):
106103
raise CastError(value, self.type)
107-
108-
def unmarshal(self, value, resolver=None, custom_formatters=None):
109-
"""Unmarshal parameter from the value."""
110-
from openapi_core.unmarshalling.schemas.factories import (
111-
SchemaUnmarshallersFactory,
112-
)
113-
unmarshallers_factory = SchemaUnmarshallersFactory(
114-
resolver, custom_formatters)
115-
unmarshaller = unmarshallers_factory.create(self)
116-
try:
117-
return unmarshaller(value)
118-
except ValueError as exc:
119-
raise UnmarshalValueError(value, self.type, exc)

openapi_core/unmarshalling/schemas/exceptions.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,6 @@ class UnmarshallerError(UnmarshalError):
1818
pass
1919

2020

21-
@attr.s(hash=True)
22-
class UnmarshalValueError(UnmarshalError):
23-
"""Failed to unmarshal value to type"""
24-
value = attr.ib()
25-
type = attr.ib()
26-
original_exception = attr.ib(default=None)
27-
28-
def __str__(self):
29-
return (
30-
"Failed to unmarshal value {value} to type {type}: {exception}"
31-
).format(
32-
value=self.value, type=self.type,
33-
exception=self.original_exception,
34-
)
35-
36-
3721
@attr.s(hash=True)
3822
class InvalidSchemaValue(ValidateError):
3923
value = attr.ib()

openapi_core/validation/request/validators.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@ def _unmarshal(self, param_or_media_type, value):
157157
if not param_or_media_type.schema:
158158
return value
159159

160-
return param_or_media_type.schema.unmarshal(
161-
value,
162-
resolver=self.spec._resolver,
163-
custom_formatters=self.custom_formatters,
160+
from openapi_core.unmarshalling.schemas.factories import (
161+
SchemaUnmarshallersFactory,
164162
)
163+
unmarshallers_factory = SchemaUnmarshallersFactory(
164+
self.spec._resolver, self.custom_formatters)
165+
unmarshaller = unmarshallers_factory.create(
166+
param_or_media_type.schema)
167+
return unmarshaller(value)

openapi_core/validation/response/validators.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,11 @@ def _unmarshal(self, param_or_media_type, value):
104104
if not param_or_media_type.schema:
105105
return value
106106

107-
return param_or_media_type.schema.unmarshal(
108-
value,
109-
resolver=self.spec._resolver,
110-
custom_formatters=self.custom_formatters,
107+
from openapi_core.unmarshalling.schemas.factories import (
108+
SchemaUnmarshallersFactory,
111109
)
110+
unmarshallers_factory = SchemaUnmarshallersFactory(
111+
self.spec._resolver, self.custom_formatters)
112+
unmarshaller = unmarshallers_factory.create(
113+
param_or_media_type.schema)
114+
return unmarshaller(value)

0 commit comments

Comments
 (0)