Skip to content

Commit 2bca252

Browse files
committed
Schema validation errors list
1 parent 8845982 commit 2bca252

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

openapi_core/schema/schemas/exceptions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ def __str__(self):
4848
class InvalidSchemaValue(ValidateError):
4949
value = attr.ib()
5050
type = attr.ib()
51+
schema_errors = attr.ib()
5152

5253
def __str__(self):
53-
return "Value {value} not valid for schema of type {type}".format(
54-
value=self.value, type=self.type)
54+
errors = list(self.schema_errors)
55+
return (
56+
"Value {value} not valid for schema of type {type}: {errors}"
57+
).format(value=self.value, type=self.type, errors=errors)
5558

5659

5760
class UnmarshallerError(UnmarshallError):

openapi_core/schema/schemas/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ def validate(self, value, resolver=None):
193193
try:
194194
return validator.validate(value)
195195
except ValidationError:
196-
# TODO: pass validation errors
197-
raise InvalidSchemaValue(value, self.type)
196+
errors_iter = validator.iter_errors(value)
197+
raise InvalidSchemaValue(value, self.type, errors_iter)
198198

199199
def unmarshal(self, value, custom_formatters=None, strict=True):
200200
"""Unmarshal parameter from the value."""

tests/integration/validation/test_petstore.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,13 @@ def test_get_pets_invalid_response(self, spec, response_validator):
175175

176176
response_result = response_validator.validate(request, response)
177177

178+
errors = response_result.errors[0].original_exception.schema_errors
178179
assert response_result.errors == [
179180
InvalidMediaTypeValue(
180181
original_exception=InvalidSchemaValue(
181182
type=SchemaType.OBJECT,
182183
value=data_json,
184+
schema_errors=errors,
183185
),
184186
),
185187
]

0 commit comments

Comments
 (0)