File size: 998 Bytes
b7720f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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())