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

32 lines
801 B
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:25:21 +00:00
class ValidateError(OpenAPISchemaError):
"""Schema validate operation error"""
pass
2019-06-18 11:39:07 +00:00
@attr.s(hash=True)
2019-10-20 12:25:21 +00:00
class InvalidSchemaValue(ValidateError):
value = attr.ib()
type = attr.ib()
2019-10-22 21:01:17 +00:00
_schema_errors = attr.ib(default=None)
_schema_errors_iter = attr.ib(factory=list)
@property
def schema_errors(self):
if self._schema_errors is None:
self._schema_errors = list(self._schema_errors_iter)
return self._schema_errors
def __str__(self):
2019-10-20 12:55:50 +00:00
return (
"Value {value} not valid for schema of type {type}: {errors}"
2019-10-22 21:01:17 +00:00
).format(value=self.value, type=self.type, errors=self.schema_errors)