2018-09-06 14:50:16 +00:00
|
|
|
import attr
|
|
|
|
|
2019-06-18 11:39:07 +00:00
|
|
|
from openapi_core.schema.exceptions import OpenAPIMappingError
|
|
|
|
|
2018-04-18 10:39:03 +00:00
|
|
|
|
|
|
|
class OpenAPISchemaError(OpenAPIMappingError):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-10-20 12:25:21 +00:00
|
|
|
@attr.s(hash=True)
|
|
|
|
class CastError(OpenAPISchemaError):
|
|
|
|
"""Schema cast operation error"""
|
|
|
|
value = attr.ib()
|
|
|
|
type = attr.ib()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Failed to cast value {value} to type {type}".format(
|
|
|
|
value=self.value, type=self.type)
|
|
|
|
|
|
|
|
|
|
|
|
class ValidateError(OpenAPISchemaError):
|
|
|
|
"""Schema validate operation error"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-10-20 12:00:14 +00:00
|
|
|
class UnmarshallError(OpenAPISchemaError):
|
2019-10-20 12:25:21 +00:00
|
|
|
"""Schema unmarshall operation error"""
|
2019-10-20 12:00:14 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s(hash=True)
|
|
|
|
class UnmarshallValueError(UnmarshallError):
|
|
|
|
"""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,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-06-18 11:39:07 +00:00
|
|
|
@attr.s(hash=True)
|
2019-10-20 12:25:21 +00:00
|
|
|
class InvalidSchemaValue(ValidateError):
|
2018-09-06 14:50:16 +00:00
|
|
|
value = attr.ib()
|
|
|
|
type = attr.ib()
|
2019-10-20 12:55:50 +00:00
|
|
|
schema_errors = attr.ib()
|
2018-09-06 14:50:16 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2019-10-20 12:55:50 +00:00
|
|
|
errors = list(self.schema_errors)
|
|
|
|
return (
|
|
|
|
"Value {value} not valid for schema of type {type}: {errors}"
|
|
|
|
).format(value=self.value, type=self.type, errors=errors)
|
2018-05-25 15:32:09 +00:00
|
|
|
|
|
|
|
|
2019-10-20 12:00:14 +00:00
|
|
|
class UnmarshallerError(UnmarshallError):
|
|
|
|
"""Unmarshaller error"""
|
2019-05-23 11:48:45 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-10-20 12:00:14 +00:00
|
|
|
@attr.s(hash=True)
|
|
|
|
class InvalidCustomFormatSchemaValue(UnmarshallerError):
|
|
|
|
"""Value failed to format with custom formatter"""
|
|
|
|
value = attr.ib()
|
|
|
|
type = attr.ib()
|
|
|
|
original_exception = attr.ib()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return (
|
|
|
|
"Failed to format value {value} to format {type}: {exception}"
|
|
|
|
).format(
|
|
|
|
value=self.value, type=self.type,
|
|
|
|
exception=self.original_exception,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s(hash=True)
|
|
|
|
class FormatterNotFoundError(UnmarshallerError):
|
|
|
|
"""Formatter not found to unmarshal"""
|
|
|
|
value = attr.ib()
|
|
|
|
type_format = attr.ib()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return (
|
|
|
|
"Formatter not found for {format} format "
|
|
|
|
"to unmarshal value {value}"
|
|
|
|
).format(format=self.type_format, value=self.value)
|
|
|
|
|
|
|
|
|
|
|
|
@attr.s(hash=True)
|
2019-05-23 11:48:45 +00:00
|
|
|
class UnmarshallerStrictTypeError(UnmarshallerError):
|
|
|
|
value = attr.ib()
|
|
|
|
types = attr.ib()
|
|
|
|
|
|
|
|
def __str__(self):
|
2019-10-20 12:00:14 +00:00
|
|
|
types = ', '.join(list(map(str, self.types)))
|
|
|
|
return "Value {value} is not one of types: {types}".format(
|
|
|
|
value=self.value, types=types)
|