mirror of
https://github.com/correl/openapi-core.git
synced 2024-11-24 19:19:56 +00:00
Merge pull request #170 from p1c2u/fix/validation-schema-errors-iter-fix
Validation schema errors iter fix
This commit is contained in:
commit
cabe512fb0
3 changed files with 14 additions and 6 deletions
|
@ -48,13 +48,19 @@ class UnmarshalValueError(UnmarshalError):
|
|||
class InvalidSchemaValue(ValidateError):
|
||||
value = attr.ib()
|
||||
type = attr.ib()
|
||||
schema_errors = attr.ib()
|
||||
_schema_errors = attr.ib(default=None)
|
||||
_schema_errors_iter = attr.ib(factory=list)
|
||||
|
||||
@property
|
||||
def schema_errors(self):
|
||||
if self._schema_errors is None:
|
||||
self._schema_errors = list(self._schema_errors_iter)
|
||||
return self._schema_errors
|
||||
|
||||
def __str__(self):
|
||||
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)
|
||||
).format(value=self.value, type=self.type, errors=self.schema_errors)
|
||||
|
||||
|
||||
class UnmarshallerError(UnmarshalError):
|
||||
|
|
|
@ -194,7 +194,8 @@ class Schema(object):
|
|||
return validator.validate(value)
|
||||
except ValidationError:
|
||||
errors_iter = validator.iter_errors(value)
|
||||
raise InvalidSchemaValue(value, self.type, errors_iter)
|
||||
raise InvalidSchemaValue(
|
||||
value, self.type, schema_errors_iter=errors_iter)
|
||||
|
||||
def unmarshal(self, value, custom_formatters=None, strict=True):
|
||||
"""Unmarshal parameter from the value."""
|
||||
|
|
|
@ -175,13 +175,14 @@ class TestPetstore(object):
|
|||
|
||||
response_result = response_validator.validate(request, response)
|
||||
|
||||
errors = response_result.errors[0].original_exception.schema_errors
|
||||
original_exc = response_result.errors[0].original_exception
|
||||
assert response_result.errors == [
|
||||
InvalidMediaTypeValue(
|
||||
original_exception=InvalidSchemaValue(
|
||||
type=SchemaType.OBJECT,
|
||||
value=data_json,
|
||||
schema_errors=errors,
|
||||
schema_errors=original_exc.schema_errors,
|
||||
schema_errors_iter=original_exc._schema_errors_iter,
|
||||
),
|
||||
),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue