-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (93 loc) · 3.29 KB
/
Copy pathvalidate-specs.yml
File metadata and controls
112 lines (93 loc) · 3.29 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: Validate Specs
on:
push:
branches:
- main
- master
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
validate-specs:
name: Validate JSON Schemas and Samples
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v5
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
- name: Install validation dependencies
run: |
python -m pip install --upgrade pip
python -m pip install jsonschema
- name: Validate schemas and samples
run: |
python - <<'PY'
import json
from pathlib import Path
from jsonschema import Draft202012Validator
pairs = [
(
"schemas/wing-type.schema.json",
"examples/wing-type.sample.json",
"Wing Type"
),
(
"schemas/message-envelope.schema.json",
"examples/message-envelope.sample.json",
"Message Envelope"
),
(
"schemas/shared-context.schema.json",
"examples/shared-context.sample.json",
"Shared Context"
),
(
"schemas/trace-reference.schema.json",
"examples/trace-reference.sample.json",
"Trace Reference"
),
]
def load_json(path_str: str):
path = Path(path_str)
if not path.exists():
raise FileNotFoundError(f"File not found: {path}")
try:
with path.open("r", encoding="utf-8") as f:
return json.load(f)
except json.JSONDecodeError as e:
raise ValueError(f"Invalid JSON in {path}: {e}") from e
print("=== Validating Multi-Wing Standard repository ===")
print()
failed = False
for schema_path, sample_path, label in pairs:
print(f"=== Validating {label} ===")
print(f"Schema: {schema_path}")
print(f"Sample: {sample_path}")
try:
schema = load_json(schema_path)
sample = load_json(sample_path)
Draft202012Validator.check_schema(schema)
validator = Draft202012Validator(schema)
errors = sorted(validator.iter_errors(sample), key=lambda e: list(e.path))
if errors:
failed = True
print(f"ERROR: {label} sample is invalid.")
for err in errors:
path = ".".join(str(p) for p in err.path) or "<root>"
print(f" - Path: {path}")
print(f" Message: {err.message}")
else:
print(f"OK: {label} sample is valid.")
except Exception as e:
failed = True
print(f"ERROR: {e}")
print()
if failed:
print("Validation failed.")
raise SystemExit(1)
print("All schema and sample validations passed.")
PY