Skip to content

Unable to reference local "urn:" URI when used in indirection (draft-07 schema) #549

Open

Description

@Svintooo

check-jsonschema seems to fail to resolve a $ref in draft-07 schema when used as indirection.

I do not rule out an error in the schema I am using, but I have personally been unable to verify any non-compliance to the spec: https://json-schema.org/draft-07

Notes:

  • The schema will work with check-jsonschema if draft-07 is changed to 2019-09 (and "definitions" changed to "$defs").
  • The schema works fine when used with helm.

Contrived example:

values.yaml:

someVal: "a string"

values.schema.json:

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "$id": "urn:my-project:helm:schemas:v1:my-helm-chart",
  "type": "object",
  "properties": {
    "someVal": {
      "$ref": "urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection"
    }
  },
  "definitions": {
    "indirection": {
      "$id": "urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection",
      "$ref": "urn:my-project:helm:schemas:v1:my-helm-chart/string-type"
    },
    "string": {
      "$id": "urn:my-project:helm:schemas:v1:my-helm-chart/string-type",
      "type": "string"
    }
  }
}

Results:

> check_jsonschema --schemafile values.schema.json values.yaml
Failure resolving $ref within schema

_WrappedReferencingError: Unresolvable: urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection
  in "/local/workspace/repos/_external/check-jsonschema/venv/lib/python3.12/site-packages/check_jsonschema/checker.py", line 85
  >>> result = self._build_result()

  caused by

  Unresolvable: urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection
    in "/local/workspace/repos/_external/check-jsonschema/venv/lib/python3.12/site-packages/jsonschema/validators.py", line 463
    >>> resolved = self._resolver.lookup(ref)

    caused by

    Unretrievable: 'urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection'
      in "/local/workspace/repos/_external/check-jsonschema/venv/lib/python3.12/site-packages/referencing/_core.py", line 682
      >>> retrieved = self._registry.get_or_retrieve(uri)

      caused by

      FileNotFoundError: [Errno 2] No such file or directory: '/local/workspace/repos/_external/check-jsonschema/urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection'
        in "/local/workspace/repos/_external/check-jsonschema/venv/lib/python3.12/site-packages/referencing/_core.py", line 428
        >>> resource = registry._retrieve(uri)

Background
At $workplace, all helm charts gets their values.schema.json generated by a tool that heavily uses $ref properties to split up the file into multiple schemas. The resulting schema works as intended with helm CLI command.

I have started running the schemas against other schema validators than helm to see if there are any differences in the validation results. I do this both for fun and for trying to find possible improvements to our schemas.

Activity

  1. MbappeWU commented on Oct 11, 2026

    @MbappeWU

    This looks like expected draft-07 behavior rather than a check-jsonschema bug: section 8.3 ("Schema References With $ref") says "All other properties in a "$ref" object MUST be ignored."

    The $id beside $ref in definitions.indirection is therefore ignored and never registered, so urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection cannot be resolved.

    On draft-07, keep that $id and move the $ref under allOf. Full schema:

    {
      "$schema": "http://json-schema.org/draft-07/schema",
      "$id": "urn:my-project:helm:schemas:v1:my-helm-chart",
      "type": "object",
      "properties": {
        "someVal": {
          "$ref": "urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection"
        }
      },
      "definitions": {
        "indirection": {
          "$id": "urn:my-project:helm:schemas:v1:my-helm-chart/unnecessary-indirection",
          "allOf": [
            {
              "$ref": "urn:my-project:helm:schemas:v1:my-helm-chart/string-type"
            }
          ]
        },
        "string": {
          "$id": "urn:my-project:helm:schemas:v1:my-helm-chart/string-type",
          "type": "string"
        }
      }
    }

    With this schema, check-jsonschema --schemafile values.schema.json values.yaml passes for someVal: "a string" and reports 1 is not of type 'string' for someVal: 1.

    Switching to 2019-09+, where $ref may have siblings, also works with $defs, as you already observed.

    Verified both with check-jsonschema 0.38.2 locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions