Spaces:
Sleeping
Sleeping
| import json | |
| from jsonschema import validate, Draft202012Validator | |
| def assert_valid(data: dict, schema_path: str): | |
| with open(schema_path, "r", encoding="utf-8") as f: | |
| schema = json.load(f) | |
| validator = Draft202012Validator(schema) | |
| errors = sorted(validator.iter_errors(data), key=lambda e: e.path) | |
| if errors: | |
| details = "\n".join([f"- {e.message} @ {'/'.join(map(str, e.path))}" for e in errors]) | |
| raise ValueError(f"Schema validation failed:\n{details}") | |