mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-28 19:19:23 +00:00
style fixes
This commit is contained in:
parent
6d8b2e5111
commit
4044483194
10 changed files with 23 additions and 27 deletions
|
@ -4,7 +4,8 @@ from openapi_core.schema.schemas.types import NoValue
|
|||
|
||||
class PrimitiveCaster(object):
|
||||
|
||||
def __init__(self, caster_callable):
|
||||
def __init__(self, schema, caster_callable):
|
||||
self.schema = schema
|
||||
self.caster_callable = caster_callable
|
||||
|
||||
def __call__(self, value):
|
||||
|
@ -12,8 +13,8 @@ class PrimitiveCaster(object):
|
|||
return value
|
||||
try:
|
||||
return self.caster_callable(value)
|
||||
except (ValueError, TypeError) as exc:
|
||||
raise CastError(exc, self.caster_callable)
|
||||
except (ValueError, TypeError):
|
||||
raise CastError(value, self.schema.type.value)
|
||||
|
||||
|
||||
class DummyCaster(object):
|
||||
|
|
|
@ -8,22 +8,24 @@ from openapi_core.casting.schemas.util import forcebool
|
|||
|
||||
class SchemaCastersFactory(object):
|
||||
|
||||
DUMMY_CASTER = DummyCaster()
|
||||
DUMMY_CASTERS = [
|
||||
SchemaType.STRING, SchemaType.OBJECT, SchemaType.ANY,
|
||||
]
|
||||
PRIMITIVE_CASTERS = {
|
||||
SchemaType.STRING: DUMMY_CASTER,
|
||||
SchemaType.INTEGER: PrimitiveCaster(int),
|
||||
SchemaType.NUMBER: PrimitiveCaster(float),
|
||||
SchemaType.BOOLEAN: PrimitiveCaster(forcebool),
|
||||
SchemaType.OBJECT: DUMMY_CASTER,
|
||||
SchemaType.ANY: DUMMY_CASTER,
|
||||
SchemaType.INTEGER: int,
|
||||
SchemaType.NUMBER: float,
|
||||
SchemaType.BOOLEAN: forcebool,
|
||||
}
|
||||
COMPLEX_CASTERS = {
|
||||
SchemaType.ARRAY: ArrayCaster,
|
||||
}
|
||||
|
||||
def create(self, schema):
|
||||
if schema.type in self.PRIMITIVE_CASTERS:
|
||||
return self.PRIMITIVE_CASTERS[schema.type]
|
||||
if schema.type in self.DUMMY_CASTERS:
|
||||
return DummyCaster()
|
||||
elif schema.type in self.PRIMITIVE_CASTERS:
|
||||
caster_callable = self.PRIMITIVE_CASTERS[schema.type]
|
||||
return PrimitiveCaster(schema, caster_callable)
|
||||
elif schema.type in self.COMPLEX_CASTERS:
|
||||
caster_class = self.COMPLEX_CASTERS[schema.type]
|
||||
return caster_class(schema=schema, casters_factory=self)
|
||||
return caster_class(schema, self)
|
||||
|
|
|
@ -10,5 +10,5 @@ class PrimitiveDeserializer(object):
|
|||
def __call__(self, value):
|
||||
try:
|
||||
return self.deserializer_callable(value)
|
||||
except (ValueError, TypeError, AttributeError) as exc:
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
raise DeserializeError(value, self.mimetype)
|
||||
|
|
|
@ -3,7 +3,6 @@ from openapi_core.deserializing.parameters.exceptions import (
|
|||
EmptyParameterValue,
|
||||
)
|
||||
from openapi_core.schema.parameters.enums import ParameterLocation
|
||||
from openapi_core.schema.schemas.types import NoValue
|
||||
|
||||
|
||||
class PrimitiveDeserializer(object):
|
||||
|
@ -22,5 +21,5 @@ class PrimitiveDeserializer(object):
|
|||
return value
|
||||
try:
|
||||
return self.deserializer_callable(value)
|
||||
except (ValueError, TypeError, AttributeError) as exc:
|
||||
except (ValueError, TypeError, AttributeError):
|
||||
raise DeserializeError(value, self.param.style)
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
"""OpenAPI core media types models module"""
|
||||
|
||||
|
||||
class MediaType(object):
|
||||
"""Represents an OpenAPI MediaType."""
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
"""OpenAPI core parameters models module"""
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
from openapi_core.schema.parameters.enums import (
|
||||
ParameterLocation, ParameterStyle,
|
||||
|
|
|
@ -6,9 +6,8 @@ from openapi_core.casting.schemas.exceptions import CastError
|
|||
from openapi_core.deserializing.exceptions import DeserializeError
|
||||
from openapi_core.schema.media_types.exceptions import InvalidContentType
|
||||
from openapi_core.schema.operations.exceptions import InvalidOperation
|
||||
from openapi_core.schema.parameters.enums import ParameterLocation
|
||||
from openapi_core.schema.parameters.exceptions import (
|
||||
OpenAPIParameterError, MissingRequiredParameter, MissingParameter,
|
||||
MissingRequiredParameter, MissingParameter,
|
||||
)
|
||||
from openapi_core.schema.paths.exceptions import InvalidPath
|
||||
from openapi_core.schema.request_bodies.exceptions import MissingRequestBody
|
||||
|
@ -192,7 +191,6 @@ class RequestValidator(object):
|
|||
deserializer = deserializers_factory.create(media_type)
|
||||
return deserializer(value)
|
||||
|
||||
|
||||
def _deserialise_parameter(self, param, value):
|
||||
from openapi_core.deserializing.parameters.factories import (
|
||||
ParameterDeserializersFactory,
|
||||
|
@ -206,7 +204,6 @@ class RequestValidator(object):
|
|||
if not param_or_media_type.schema:
|
||||
return value
|
||||
|
||||
from openapi_core.casting.schemas.exceptions import CastError
|
||||
from openapi_core.casting.schemas.factories import SchemaCastersFactory
|
||||
casters_factory = SchemaCastersFactory()
|
||||
caster = casters_factory.create(param_or_media_type.schema)
|
||||
|
|
|
@ -121,13 +121,11 @@ class ResponseValidator(object):
|
|||
if not param_or_media_type.schema:
|
||||
return value
|
||||
|
||||
from openapi_core.casting.schemas.exceptions import CastError
|
||||
from openapi_core.casting.schemas.factories import SchemaCastersFactory
|
||||
casters_factory = SchemaCastersFactory()
|
||||
caster = casters_factory.create(param_or_media_type.schema)
|
||||
return caster(value)
|
||||
|
||||
|
||||
def _unmarshal(self, param_or_media_type, value):
|
||||
if not param_or_media_type.schema:
|
||||
return value
|
||||
|
|
|
@ -105,8 +105,7 @@ class TestFlaskOpenAPIDecorator(object):
|
|||
),
|
||||
'status': 400,
|
||||
'title': (
|
||||
"Failed to cast value invalid literal for int() with "
|
||||
"base 10: 'invalidparameter' to type <class 'int'>"
|
||||
"Failed to cast value invalidparameter to type integer"
|
||||
)
|
||||
}
|
||||
]
|
||||
|
|
|
@ -92,8 +92,7 @@ class TestFlaskOpenAPIView(object):
|
|||
),
|
||||
'status': 400,
|
||||
'title': (
|
||||
"Failed to cast value invalid literal for int() with "
|
||||
"base 10: 'invalidparameter' to type <class 'int'>"
|
||||
"Failed to cast value invalidparameter to type integer"
|
||||
)
|
||||
}
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue