Skip to content

Commit e49d52c

Browse files
committed
Add control-plane example validator
1 parent 22158dd commit e49d52c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python3
2+
from __future__ import annotations
3+
4+
import json
5+
import sys
6+
from pathlib import Path
7+
8+
import jsonschema
9+
10+
ROOT = Path(__file__).resolve().parents[1]
11+
PAIRS = [
12+
(ROOT / "schemas" / "control-plane" / "ReleaseSet.json", ROOT / "examples" / "release_set.json"),
13+
(ROOT / "schemas" / "control-plane" / "Fingerprint.json", ROOT / "examples" / "fingerprint.json"),
14+
]
15+
16+
17+
def main() -> int:
18+
checks: dict[str, bool] = {}
19+
for schema_path, example_path in PAIRS:
20+
schema = json.loads(schema_path.read_text(encoding="utf-8"))
21+
example = json.loads(example_path.read_text(encoding="utf-8"))
22+
resolver = jsonschema.validators.validator_for(schema)
23+
resolver.check_schema(schema)
24+
validator = resolver(schema, registry=jsonschema.validators.SPECIFICATIONS)
25+
# Resolve local legacy refs by changing cwd-like base through a RefResolver fallback for older jsonschema behavior.
26+
# jsonschema 4.x resolves relative refs against the schema id; these wrapper schemas reference local legacy files.
27+
legacy_schema_path = schema_path.with_name(schema["allOf"][0]["$ref"])
28+
legacy_schema = json.loads(legacy_schema_path.read_text(encoding="utf-8"))
29+
jsonschema.validate(example, legacy_schema)
30+
checks[example_path.name] = True
31+
print(json.dumps({"ok": all(checks.values()), "checks": checks}, indent=2, sort_keys=True))
32+
return 0
33+
34+
35+
if __name__ == "__main__":
36+
raise SystemExit(main())

0 commit comments

Comments
 (0)