-
Notifications
You must be signed in to change notification settings - Fork 32
/
validator.py
53 lines (40 loc) · 1.29 KB
/
validator.py
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
#!/usr/bin/env python3
"""
Script to validate resources
"""
from pathlib import Path
import json
from jsonschema import validate
def get_category_list():
"""
Walk the current directory and get a list of all subdirectories at that
level. These are the "categories" of resources.
"""
dirs = []
for path in Path('.').rglob('*.json'):
path = str(path)
if "venv" not in path:
dirs.append(path)
return dirs
def get_schema():
"""
Get resource schema content
"""
with open("resource.schema", "r", encoding='UTF-8') as schema_content:
return schema_content.read()
def validator(schema, resources):
"""
Given the resource.schema validate if a give resource index adheres to the rules
"""
total_resources = 0
for resource in resources:
with open(resource, "r", encoding='UTF-8') as res:
data = json.loads(res.read())
total_resources = total_resources + len(data["resources"])
validate(instance=data, schema=schema)
print("All resources adhere to the schema ✅")
print("Total Resources:", total_resources)
if __name__ == "__main__":
resources = get_category_list()
json_schema = json.loads(get_schema())
validator(json_schema, resources)