summaryrefslogtreecommitdiff
path: root/lib/python/qmk/json_schema.py
diff options
context:
space:
mode:
authorErovia <Erovia@users.noreply.github.com>2022-02-28 20:02:39 +0000
committerGitHub <noreply@github.com>2022-02-28 20:02:39 +0000
commitfbfd5312b995a32af690c183cad0dc988f695e89 (patch)
treebf241a475ec51b79d6427ac422f197b6d3720661 /lib/python/qmk/json_schema.py
parent779c7debcfff1a4a3ad578a0c12bdd50cba11039 (diff)
CLI: Validate JSON keymap input (#16261)
* Fix schema validator It should use the passed schema. * Add required attributes to keymap schema * Rework subcommands to validate the JSON keymaps The 'compile', 'flash' and 'json2c' subcommands were reworked to add JSON keymap validation so error is reported for non-JSON and non-compliant-JSON inputs. * Fix required fields in keymap schema * Add tests * Fix compiling keymaps directly from keymap directory * Schema should not require version for now.
Diffstat (limited to 'lib/python/qmk/json_schema.py')
-rw-r--r--lib/python/qmk/json_schema.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/python/qmk/json_schema.py b/lib/python/qmk/json_schema.py
index ffc7c6bcd1..2b48782fbb 100644
--- a/lib/python/qmk/json_schema.py
+++ b/lib/python/qmk/json_schema.py
@@ -16,7 +16,11 @@ def json_load(json_file):
Note: file must be a Path object.
"""
try:
- return hjson.load(json_file.open(encoding='utf-8'))
+ # Get the IO Stream for Path objects
+ # Not necessary if the data is provided via stdin
+ if isinstance(json_file, Path):
+ json_file = json_file.open(encoding='utf-8')
+ return hjson.load(json_file)
except (json.decoder.JSONDecodeError, hjson.HjsonDecodeError) as e:
cli.log.error('Invalid JSON encountered attempting to load {fg_cyan}%s{fg_reset}:\n\t{fg_red}%s', json_file, e)
@@ -62,7 +66,7 @@ def create_validator(schema):
"""Creates a validator for the given schema id.
"""
schema_store = compile_schema_store()
- resolver = jsonschema.RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
+ resolver = jsonschema.RefResolver.from_schema(schema_store[schema], store=schema_store)
return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate