mirror of
https://github.com/correl/openapi-core.git
synced 2024-12-29 11:09:25 +00:00
Schema validation errors list
This commit is contained in:
parent
88459829ad
commit
2bca2526f2
3 changed files with 9 additions and 4 deletions
|
@ -48,10 +48,13 @@ class UnmarshallValueError(UnmarshallError):
|
|||
class InvalidSchemaValue(ValidateError):
|
||||
value = attr.ib()
|
||||
type = attr.ib()
|
||||
schema_errors = attr.ib()
|
||||
|
||||
def __str__(self):
|
||||
return "Value {value} not valid for schema of type {type}".format(
|
||||
value=self.value, type=self.type)
|
||||
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)
|
||||
|
||||
|
||||
class UnmarshallerError(UnmarshallError):
|
||||
|
|
|
@ -193,8 +193,8 @@ class Schema(object):
|
|||
try:
|
||||
return validator.validate(value)
|
||||
except ValidationError:
|
||||
# TODO: pass validation errors
|
||||
raise InvalidSchemaValue(value, self.type)
|
||||
errors_iter = validator.iter_errors(value)
|
||||
raise InvalidSchemaValue(value, self.type, errors_iter)
|
||||
|
||||
def unmarshal(self, value, custom_formatters=None, strict=True):
|
||||
"""Unmarshal parameter from the value."""
|
||||
|
|
|
@ -175,11 +175,13 @@ class TestPetstore(object):
|
|||
|
||||
response_result = response_validator.validate(request, response)
|
||||
|
||||
errors = response_result.errors[0].original_exception.schema_errors
|
||||
assert response_result.errors == [
|
||||
InvalidMediaTypeValue(
|
||||
original_exception=InvalidSchemaValue(
|
||||
type=SchemaType.OBJECT,
|
||||
value=data_json,
|
||||
schema_errors=errors,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue