| import argparse |
| import json |
| from pathlib import Path |
|
|
| from jsonschema import Draft7Validator |
|
|
|
|
| def validate(schema_path: Path, json_path: Path) -> int: |
| schema = json.loads(schema_path.read_text(encoding="utf-8")) |
| payload = json.loads(json_path.read_text(encoding="utf-8")) |
|
|
| validator = Draft7Validator(schema) |
| errors = sorted(validator.iter_errors(payload), key=lambda e: list(e.path)) |
|
|
| if not errors: |
| print("VALID") |
| return 0 |
|
|
| print("INVALID") |
| for err in errors[:50]: |
| path = ".".join(str(p) for p in err.path) |
| print(f"- {path}: {err.message}") |
| return 1 |
|
|
|
|
| def main() -> int: |
| parser = argparse.ArgumentParser(description="Validate a GravityLLM scene JSON against the Spatial9Scene schema.") |
| parser.add_argument("schema_path", type=Path) |
| parser.add_argument("json_path", type=Path) |
| args = parser.parse_args() |
| return validate(args.schema_path, args.json_path) |
|
|
|
|
| if __name__ == "__main__": |
| raise SystemExit(main()) |
|
|