Skip to content

$ref that passes lint but fails in validate as error: Could not resolve schema reference #185

Closed
@robbat2

Description

@robbat2

I'm trying to look at alternate options for validation against JSON Schema for https://github.com/backstage/backstage - and I think I found a case where the schema is valid, but jsonschema fails to handle the $ref behavior correctly.

AJV does handle this case correctly. P.S. Globbing for the -r argument or accepting a list of files as another file would help in making the commandline much shorter.

Shorter part of the error:

error: Could not resolve schema reference
  #reference
    at schema location "/definitions/relation/properties/target/$ref"

This is here in the schema

If I remove target from the schema, as it is deprecated, I get a similar error for #statusItem:

error: Could not resolve schema reference
  #statusItem
    at schema location "/definitions/status/properties/items/items/$ref"

Against a checkout of Backstage:

$ export BIN=/tmp/jsonschema.bug.lVrZDy/jsonschema-4.1.5-linux-x86_64/bin/jsonschema
$ export MAINSCHEMA=/code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json
rjohnson@rjohnson-1:/code/gh/backstage/backstage$ ${BIN} lint \
$(find packages -name '*.schema.json'  -printf " -r %h/%f\n" |sort | uniq ) \
${MAINSCHEMA}   -v
Linting: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/Entity.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/EntityEnvelope.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/EntityMeta.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/API.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Domain.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Group.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Location.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Resource.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/System.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/User.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/shared/common.schema.json
PASS: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json


$ ${BIN} validate $(find packages -name '*.schema.json'  -printf " -r %h/%f\n" |sort | uniq ) ${MAINSCHEMA} /code/gh/coreweave/backstage/data/e
xample_catalogs/observability/mimir/catalog.yaml    -v
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/Entity.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/EntityEnvelope.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/EntityMeta.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/API.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Component.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Domain.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Group.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Location.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/Resource.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/System.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/kinds/User.v1alpha1.schema.json
Importing schema into the resolution context: /code/gh/backstage/backstage/packages/catalog-model/src/schema/shared/common.schema.json
error: Could not resolve schema reference
  #reference
    at schema location "/definitions/relation/properties/target/$ref"

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