Schema validation errors list

This commit is contained in:
p1c2u 2019-10-20 13:55:50 +01:00
parent 88459829ad
commit 2bca2526f2
3 changed files with 9 additions and 4 deletions

View file

@ -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):

View file

@ -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."""

View file

@ -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,
),
),
]