Skip to content

Ref resolve failure when using custom metaschema #293

@stenbein

Description

@stenbein

On July 12th it was noticed that our github action using check-jsonschema was failing. No update had been applied to the code so it was believed to be a build time/runtime issue. The following error appears:

Failure resolving $ref within schema

_RefResolutionError: Expecting value: line 1 column 1 (char 0)
  in "/root/.cache/pre-commit/repoef89ztua/py_env-python3.9/lib/python3.9/site-packages/check_jsonschema/checker.py", line 77
  >>> result = self._build_result()

  caused by

  JSONDecodeError: Expecting value: line 1 column 1 (char 0)
    in "/root/.cache/pre-commit/repoef89ztua/py_env-python3.9/lib/python3.9/site-packages/jsonschema/validators.py", line 1095
    >>> document = self.resolve_remote(url)

    caused by

    JSONDecodeError: Expecting value: line 1 column 1 (char 0)
      in "/root/.cache/pre-commit/repoef89ztua/py_env-python3.9/lib/python3.9/site-packages/requests/models.py", line 971
      >>> return complexjson.loads(self.text, **kwargs)

      caused by

      StopIteration: 0
        in "/usr/local/lib/python3.9/json/decoder.py", line 353
        >>> obj, end = self.scan_once(s, idx)

        caused by

        KeyError: 'https://json-schema.org/draft/2020-12/meta/meta/applicator'
          in "/root/.cache/pre-commit/repoef89ztua/py_env-python3.9/lib/python3.9/site-packages/jsonschema/validators.py", line 1092
          >>> document = self.store[url]

In 'https://json-schema.org/draft/2020-12/meta/meta/applicator' the second meta doesn't exist. If you monkey patch the code to replace 'meta/meta/' with 'meta' the code will proceed to fail on meta/meta/meta/. Eventually it will run correctly if you repeat this several times.

Back ground:
We have a slightly modified Draft202012 metaschema with an added "unevaluatedProperties": false to catch typos. This is run as a github action using the following pre-commit config.

 - repo: https://github.com/python-jsonschema/check-jsonschema
    rev: 0.20.0
    hooks:
      - id: check-jsonschema
        files: ^src/common/schemas/.*\.json$
        args: [--schemafile, src/common/config/meta_schema.json]

EDIT: Using the meta schema directly with jsonschema does not cause an error. The error occurs when using check-jsonschema v 0.8 or later.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions