cti-stix-validator icon indicating copy to clipboard operation
cti-stix-validator copied to clipboard

Get string representation of validation results the way print_results() displays

Open jondricek opened this issue 3 years ago • 1 comments

It would be great to be able to get the results of the stix2validator.print_results() function as a string representation. Take the base example currently in the Readme:

from stix2validator import validate_file, print_results

results = validate_file("stix_file.json")
print_results(results)

It would be nice to do e.g. foo = print_results(results) or something similar to get that as a string to work with.

Alternately maybe the results variable (a stix2validator.validators.FileValidationResults object) could have a __repr__ function built into it that provides the same output? If it went that direction it could probably make use of the FileValidationResults.as_dict() function here. Maybe?

Any thoughts on best way to implement this before I go off and make something up that works for me and do a pull request?

jondricek avatar May 03 '22 21:05 jondricek

It might make sense to define __str__ on the FileValidationResults class, that calls .as_dict() as you propose. Then print_results() could aggregate the string representations of all the results and return it after it calls .log() on them.

clenk avatar May 09 '22 14:05 clenk