Skip to content

Throw a better error to distinguish relative meta-schema references #1912

@jviotti

Description

@jviotti

According to the JSON Schema specification (https://json-schema.org/draft/2020-12/json-schema-core#section-8.1.1-2), relative meta-schema references are not permitted. We obey this, but in such case (for example when running base_dialect()), we throw a standard SchemaResolutionError that can leave some users confused.

For example, consider this case:

{ "$schema": "../meta.json" }

And this meta-schema at the corresponding relative location:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$vocabulary": { "https://json-schema.org/draft/2020-12/vocab/core": true },
  "$dynamicAnchor": "meta",
  "$ref": "https://json-schema.org/draft/2020-12/meta/core"
}

When running this in the CLI, we would get:

error: Could not resolve the metaschema of the schema
  ../meta.json

This is likely because you forgot to import such schema using --resolve/-r

Instead, we should have a new SchemaRelativeMetaschemaResolutionError error (that subclasses SchemaResolutionError) to better react to this case and present information that the average user can actually understand.

Cases to consider seem to include:

  • base_dialect() (for performance reasons, only parse the URI when we are about to throw SchemaResolutionError)
  • dialect() (this one probably does not need to check anything and we can rely on its consumers to do so when appropriate)

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