oasis-open / cti-stix-validator

OASIS TC Open Repository: Validator for STIX 2.0 JSON normative requirements and best practices
https://stix2-validator.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
50 stars 41 forks source link

print_results: 'ObjectValidationResults' object is not iterable #66

Closed cyberfox1 closed 6 years ago

cyberfox1 commented 6 years ago
from stix2validator import validate_string, print_results    
results = validate_string(sample.stix2)      
print_results(results)     

Produces:

File "lib/python3.6/site-packages/stix2validator/output.py", line 152, in print_results for file_result in sorted(results, key=operator.attrgetter("filepath")): TypeError: 'ObjectValidationResults' object is not iterable

Using:

stix2-validator==1.0.1 Python 3.6.3

gtback commented 6 years ago

Thanks for reporting this, @cyberfox1 . We ran into this issue in the stix-elevator. validate_string doesn't return a list of FileValidationResults objects, like print_results expects (instead, it returns ObjectValidationResults).

Our workaround in the stix-elevator was to wrap the ObjectValidationResults in a list of FileValidationResults before calling print_results.

Short-term, we should update the documentation to remove this invalid example. Longer-term, we need to update print_results to handle other types of input, or create other functions to accomplish the same thing.

Thanks again!