aboutsummaryrefslogtreecommitdiff
path: root/lib/python/qmk/json_schema.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python/qmk/json_schema.py')
-rw-r--r--lib/python/qmk/json_schema.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/python/qmk/json_schema.py b/lib/python/qmk/json_schema.py
index cbc5bff51..ffc7c6bcd 100644
--- a/lib/python/qmk/json_schema.py
+++ b/lib/python/qmk/json_schema.py
@@ -2,6 +2,7 @@
2""" 2"""
3import json 3import json
4from collections.abc import Mapping 4from collections.abc import Mapping
5from functools import lru_cache
5from pathlib import Path 6from pathlib import Path
6 7
7import hjson 8import hjson
@@ -25,6 +26,7 @@ def json_load(json_file):
25 exit(1) 26 exit(1)
26 27
27 28
29@lru_cache(maxsize=0)
28def load_jsonschema(schema_name): 30def load_jsonschema(schema_name):
29 """Read a jsonschema file from disk. 31 """Read a jsonschema file from disk.
30 """ 32 """
@@ -39,8 +41,9 @@ def load_jsonschema(schema_name):
39 return json_load(schema_path) 41 return json_load(schema_path)
40 42
41 43
42def create_validator(schema): 44@lru_cache(maxsize=0)
43 """Creates a validator for the given schema id. 45def compile_schema_store():
46 """Compile all our schemas into a schema store.
44 """ 47 """
45 schema_store = {} 48 schema_store = {}
46 49
@@ -51,6 +54,14 @@ def create_validator(schema):
51 continue 54 continue
52 schema_store[schema_data['$id']] = schema_data 55 schema_store[schema_data['$id']] = schema_data
53 56
57 return schema_store
58
59
60@lru_cache(maxsize=0)
61def create_validator(schema):
62 """Creates a validator for the given schema id.
63 """
64 schema_store = compile_schema_store()
54 resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store) 65 resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
55 66
56 return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate 67 return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate