diff --git a/openapi_core/schema/schemas/exceptions.py b/openapi_core/schema/schemas/exceptions.py index eaa63e9..9428190 100644 --- a/openapi_core/schema/schemas/exceptions.py +++ b/openapi_core/schema/schemas/exceptions.py @@ -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): diff --git a/openapi_core/schema/schemas/models.py b/openapi_core/schema/schemas/models.py index a1bc874..7bc4ad8 100644 --- a/openapi_core/schema/schemas/models.py +++ b/openapi_core/schema/schemas/models.py @@ -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.""" diff --git a/tests/integration/validation/test_petstore.py b/tests/integration/validation/test_petstore.py index a7eba0e..38ab8ba 100644 --- a/tests/integration/validation/test_petstore.py +++ b/tests/integration/validation/test_petstore.py @@ -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, ), ), ]