fileapi_validate_schema.py 750 B

1234567891011121314151617181920212223
  1. import json
  2. import jsonschema
  3. import sys
  4. # First argument is a file containing the list of files to check
  5. with open(sys.argv[1], "r", encoding="utf-8") as file_list:
  6. files_to_check = [line.strip() for line in file_list if line.strip()]
  7. # Second argument is the schema file
  8. with open(sys.argv[2], "r", encoding="utf-8-sig") as f:
  9. schema = json.load(f)
  10. # Check each file against the schema
  11. for file_path in files_to_check:
  12. try:
  13. with open(file_path, "r", encoding="utf-8-sig") as f:
  14. contents = json.load(f)
  15. # The following raises an exception if validation fails
  16. jsonschema.validate(contents, schema)
  17. except Exception as e:
  18. print(f"Failed to validate file {file_path}: {e}")
  19. raise