cyclonedx.validation.SchemabasedValidator defines only a single method available: .validate_str(), which returns only the first problem found.
I would like to ask for an extension of the interface with a new method iterate_errors() to iterate over all the problems.
This could be used to add some smartness finding the most helpful error[s] - something like best_match in https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py do.
The underlying libraries already have support for it:
jsonschema has Validator.iter_errors():
https://github.com/python-jsonschema/jsonschema/blob/f5cfc0ead76a8fc69db040cd94ed3a5e505dca81/jsonschema/protocols.py#L169-L172
Have not looked deeper into the XML case, but it is probably also available, as only the last error is returned (L71):
|
def validate_str(self, data: str) -> Optional[ValidationError]: |
|
return self._validata_data( |
|
xml_fromstring( # nosec B320 |
|
bytes(data, encoding='utf8'), |
|
parser=self.__xml_parser)) |
|
|
|
def _validata_data(self, data: Any) -> Optional[ValidationError]: |
|
validator = self._validator # may throw on error that MUST NOT be caught |
|
if not validator.validate(data): |
|
return ValidationError(validator.error_log.last_error) |
|
return None |
cyclonedx.validation.SchemabasedValidator defines only a single method available:
.validate_str(), which returns only the first problem found.I would like to ask for an extension of the interface with a new method
iterate_errors()to iterate over all the problems.This could be used to add some smartness finding the most helpful error[s] - something like
best_matchin https://github.com/python-jsonschema/jsonschema/blob/main/jsonschema/exceptions.py do.The underlying libraries already have support for it:
jsonschemahasValidator.iter_errors():https://github.com/python-jsonschema/jsonschema/blob/f5cfc0ead76a8fc69db040cd94ed3a5e505dca81/jsonschema/protocols.py#L169-L172
Have not looked deeper into the XML case, but it is probably also available, as only the last error is returned (L71):
cyclonedx-python-lib/cyclonedx/validation/xml.py
Lines 62 to 72 in 1a932a2