Skip to content

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

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):

defvalidate_str(self, data: str) ->Optional[ValidationError]:
returnself._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
ifnotvalidator.validate(data):
returnValidationError(validator.error_log.last_error)
returnNone

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions