1
0
Fork 0

Additional schema fixes (#17414)

This commit is contained in:
Joel Challis 2022-06-18 06:30:46 +01:00 committed by GitHub
parent 7b3ee1db8c
commit 17ec1650fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 64 deletions

View file

@ -5,7 +5,7 @@ Compile an info.json for a particular keyboard and pretty-print it.
import json
from argcomplete.completers import FilesCompleter
from jsonschema import Draft7Validator, RefResolver, validators
from jsonschema import Draft202012Validator, RefResolver, validators
from milc import cli
from pathlib import Path
@ -18,7 +18,7 @@ from qmk.path import is_keyboard, normpath
def pruning_validator(validator_class):
"""Extends Draft7Validator to remove properties that aren't specified in the schema.
"""Extends Draft202012Validator to remove properties that aren't specified in the schema.
"""
validate_properties = validator_class.VALIDATORS["properties"]
@ -37,10 +37,10 @@ def strip_info_json(kb_info_json):
"""Remove the API-only properties from the info.json.
"""
schema_store = compile_schema_store()
pruning_draft_7_validator = pruning_validator(Draft7Validator)
pruning_draft_validator = pruning_validator(Draft202012Validator)
schema = schema_store['qmk.keyboard.v1']
resolver = RefResolver.from_schema(schema_store['qmk.keyboard.v1'], store=schema_store)
validator = pruning_draft_7_validator(schema, resolver=resolver).validate
validator = pruning_draft_validator(schema, resolver=resolver).validate
return validator(kb_info_json)

View file

@ -68,11 +68,7 @@ def create_validator(schema):
schema_store = compile_schema_store()
resolver = jsonschema.RefResolver.from_schema(schema_store[schema], store=schema_store)
# TODO: Remove this after the jsonschema>=4 requirement had time to reach users
try:
return jsonschema.Draft202012Validator(schema_store[schema], resolver=resolver).validate
except AttributeError:
return jsonschema.Draft7Validator(schema_store[schema], resolver=resolver).validate
return jsonschema.Draft202012Validator(schema_store[schema], resolver=resolver).validate
def validate(data, schema):