forked from secondlife/lsl-definitions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
33 lines (27 loc) · 1.14 KB
/
validate.py
File metadata and controls
33 lines (27 loc) · 1.14 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
#!/bin/env python3
# coding: utf-8
import json
import sys
import yaml
import jsonschema
def validate_lsl_definitions_via_jsonschema() -> None:
with open("lsl_definitions.schema.json", "r", encoding="utf-8") as schema_file:
schemadata = json.load(schema_file)
with open("lsl_definitions.yaml", "r", encoding="utf-8") as yaml_file:
yamldata = yaml.safe_load(yaml_file)
try:
jsonschema.validate(instance=yamldata, schema=schemadata)
print("\nSUCCESS: Valid against the schema")
except jsonschema.exceptions.ValidationError as e:
print("\nVALIDATION ERROR: INVALID", file=sys.stderr)
print(f" Message: {e.message}", file=sys.stderr)
print(f" Path: {' -> '.join(map(str, e.path))}", file=sys.stderr)
print(f" Schema Path: {' -> '.join(map(str, e.schema_path))}", file=sys.stderr)
raise e
except jsonschema.exceptions.SchemaError as e:
print("\nSCHEMA ERROR: The schema is invalid", file=sys.stderr)
print(f" Message: {e.message}", file=sys.stderr)
raise e
except Exception as e:
print(f"\nOh no ...: {e}", file=sys.stderr)
raise e