-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlux-schema-test.py
More file actions
70 lines (54 loc) · 2.16 KB
/
lux-schema-test.py
File metadata and controls
70 lines (54 loc) · 2.16 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
import os
import json
import requests
from jsonschema import validate, Draft202012Validator
from jsonschema.exceptions import ValidationError
from jsonschema._utils import find_additional_properties
from referencing import Registry, Resource
schema_dir = "schema"
corefn = os.path.join(schema_dir, f"core.json")
fh = open(corefn)
core_json = json.load(fh)
fh.close()
schema = Resource.from_contents(core_json)
registry = Registry().with_resources(
[
("https://linked.art/api/1.0/schema/core.json", schema),
("core.json", schema)
],
)
instance = "https://lux.collections.yale.edu/data/person/68e84c09-5159-4f8b-ae5c-0c9145d3b6fe"
schemafn = os.path.join(schema_dir, f"person.json")
instance = "https://lux.collections.yale.edu/data/object/047181f4-2fdf-43fd-abbe-f16d7f9edc10"
schemafn = os.path.join(schema_dir, f"object.json")
instance = "https://lux.collections.yale.edu/data/concept/b2f01ce2-339e-43d1-9dc6-68c728337b96"
schemafn = os.path.join(schema_dir, f"concept.json")
instance = "https://lux.collections.yale.edu/data/group/ed771376-2583-41ce-a4fd-649320c72a42"
schemafn = os.path.join(schema_dir, f"group.json")
instance = "https://lux.collections.yale.edu/data/set/82e98f20-01e9-47d9-95a3-5b0f2a31d17e"
schemafn = os.path.join(schema_dir, f"set.json")
instance = "https://lux.collections.yale.edu/data/activity/291d650f-9052-45ba-a7d1-b7b75aa2a5bd"
schemafn = os.path.join(schema_dir, f"event.json")
fh = open(schemafn)
schema = json.load(fh)
fh.close()
v = Draft202012Validator(schema, registry=registry)
resp = requests.get(instance)
data = resp.json()
allow_underscore_props = True
print("-"*120)
print("Processing: %s" % instance)
errs = []
for error in v.iter_errors(data):
if error.validator == 'additionalProperties':
aps = []
for ap in find_additional_properties(error.instance, error.schema):
if ap[0] != '_':
aps.append(ap)
if not aps:
continue
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!")