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.
This commit is contained in:
parent
779c7debcf
commit
fbfd5312b9
6 changed files with 47 additions and 18 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue