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): class InvalidSchemaValue(ValidateError):
value = attr.ib() value = attr.ib()
type = attr.ib() type = attr.ib()
schema_errors = attr.ib()
def __str__(self): def __str__(self):
return "Value {value} not valid for schema of type {type}".format( errors = list(self.schema_errors)
value=self.value, type=self.type) return (
"Value {value} not valid for schema of type {type}: {errors}"
).format(value=self.value, type=self.type, errors=errors)
class UnmarshallerError(UnmarshallError): class UnmarshallerError(UnmarshallError):

View file

@ -193,8 +193,8 @@ class Schema(object):
try: try:
return validator.validate(value) return validator.validate(value)
except ValidationError: except ValidationError:
# TODO: pass validation errors errors_iter = validator.iter_errors(value)
raise InvalidSchemaValue(value, self.type) raise InvalidSchemaValue(value, self.type, errors_iter)
def unmarshal(self, value, custom_formatters=None, strict=True): def unmarshal(self, value, custom_formatters=None, strict=True):
"""Unmarshal parameter from the value.""" """Unmarshal parameter from the value."""

View file

@ -175,11 +175,13 @@ class TestPetstore(object):
response_result = response_validator.validate(request, response) response_result = response_validator.validate(request, response)
errors = response_result.errors[0].original_exception.schema_errors
assert response_result.errors == [ assert response_result.errors == [
InvalidMediaTypeValue( InvalidMediaTypeValue(
original_exception=InvalidSchemaValue( original_exception=InvalidSchemaValue(
type=SchemaType.OBJECT, type=SchemaType.OBJECT,
value=data_json, value=data_json,
schema_errors=errors,
), ),
), ),
] ]