Skip to content

feat: extend validation interface with new method to iterate over all the problems #828

@e3krisztian

Description

@e3krisztian

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions