diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f06f69d72..5b9f3f5e8 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,8 @@ Unreleased - Added support for Python 3.15 . - Removed support for Python 3.10 . - The build backend has been updated from setuptools to flit. +- When running with a builtin schema, ``check-jsonschema`` will now skip + the metaschema check as an optimization. 0.38.2 ------ diff --git a/src/check_jsonschema/schema_loader/main.py b/src/check_jsonschema/schema_loader/main.py index ef808becd..1e1b0c534 100644 --- a/src/check_jsonschema/schema_loader/main.py +++ b/src/check_jsonschema/schema_loader/main.py @@ -75,6 +75,7 @@ def get_validator( class SchemaLoader(SchemaLoaderBase): validator_class: type[jsonschema.protocols.Validator] | None = None disable_cache: bool = True + validate_schema: t.ClassVar[bool] = True def __init__( self, @@ -169,7 +170,8 @@ def _get_validator( # get the correct validator class and check the schema under its metaschema validator_cls = jsonschema.validators.validator_for(schema) - _check_schema(validator_cls, schema, regex_impl=regex_impl) + if self.validate_schema: + _check_schema(validator_cls, schema, regex_impl=regex_impl) else: # for a user-provided validator class, don't check_schema # on the grounds that it might *not* be valid but the user wants to use @@ -241,6 +243,10 @@ def _dialect_of_schema(schema: dict[str, t.Any] | bool) -> str | None: class BuiltinSchemaLoader(SchemaLoader): + # disable schema validation for builtin schemas + # they are already checked under the metaschema checker when they are updated/added + validate_schema: t.ClassVar[bool] = False + def __init__(self, schema_name: str, *, base_uri: str | None = None) -> None: self.schema_name = schema_name self.base_uri = base_uri