-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathschema-test.py
More file actions
47 lines (38 loc) · 1.07 KB
/
schema-test.py
File metadata and controls
47 lines (38 loc) · 1.07 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
import json
import jsonschema
import os
from jsonschema import validate, Draft7Validator
from jsonschema.exceptions import ValidationError
import json
model_dirs = {
# "place": "place",
"person": "person",
"group": "group",
"object": "object"
}
base_instance_dir = "../linked.art/content/example"
base_instance_dir = "../articular/data"
schema_dir = "schema"
for (k,v) in model_dirs.items():
schemafn = os.path.join(schema_dir, f"{v}.json")
fh = open(schemafn)
schema = json.load(fh)
fh.close()
v = Draft7Validator(schema)
exampledir = os.path.join(base_instance_dir, k)
files = os.listdir(exampledir)
for f in files:
if f.endswith('.json'):
fn = os.path.join(exampledir, f)
print("-"*120)
print("Processing: %s" % fn)
fh = open(fn)
data = json.load(fh)
fh.close()
errs = []
for error in v.iter_errors(data):
errs.append(error)
# print(error.absolute_schema_path) <-- this is the current path through the schema
print(f" /{'/'.join([str(x) for x in error.absolute_path])} --> {error.message} ")
if not errs:
print(" Validated!")