Skip to content

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

@Svintooo

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.

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