openapi-core/openapi_core/schema/schemas/exceptions.py

127 lines
3.1 KiB
Python
Raw Normal View History

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:00:14 +00:00
class UnmarshallError(OpenAPISchemaError):
"""Unmarshall operation error"""
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)
2018-08-05 12:40:34 +00:00
class NoValidSchema(OpenAPISchemaError):
value = attr.ib()
def __str__(self):
return "No valid schema found for value: {0}".format(self.value)
2018-08-05 12:40:34 +00:00
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2018-08-05 12:40:34 +00:00
class UndefinedItemsSchema(OpenAPISchemaError):
type = attr.ib()
def __str__(self):
return "Null value for schema type {0}".format(self.type)
2018-08-05 12:40:34 +00:00
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2018-04-18 10:39:03 +00:00
class InvalidSchemaValue(OpenAPISchemaError):
msg = attr.ib()
value = attr.ib()
type = attr.ib()
def __str__(self):
return self.msg.format(value=self.value, type=self.type)
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2018-04-18 10:39:03 +00:00
class UndefinedSchemaProperty(OpenAPISchemaError):
extra_props = attr.ib()
def __str__(self):
2019-10-20 12:00:14 +00:00
return "Extra unexpected properties found in schema: {0}".format(
self.extra_props)
2018-04-18 10:39:03 +00:00
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2018-09-12 16:43:31 +00:00
class InvalidSchemaProperty(OpenAPISchemaError):
property_name = attr.ib()
original_exception = attr.ib()
def __str__(self):
2019-10-20 12:00:14 +00:00
return "Invalid schema property {0}: {1}".format(
self.property_name, self.original_exception)
2018-04-18 10:39:03 +00:00
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2018-04-18 10:39:03 +00:00
class MissingSchemaProperty(OpenAPISchemaError):
property_name = attr.ib()
def __str__(self):
return "Missing schema property: {0}".format(self.property_name)
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)