Skip to content

🧹 Clarification: usage of non-canonical identifiers in $schema #1590

Open
@karenetheridge

Description

@karenetheridge

What is unclear?

Is it legal to use a non-canonical identifier in a $schema keyword to refer to a metaschema?

e.g. if I have this document:

{
  "$id": "https://example.com/some_document",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "my_embedded_metaschema": {
      "$id": "https://example.com/my_embedded_metaschema",
      "$vocabulary": {
        ...
      }
    },
    ...
  }
}

..and use the embedded metaschema in another document, can I reference it using a non-canonical identifier?

{
  "$id": "https://example.com/another_document",
  "$schema": "https://example.com/some_document#/$defs/my_embedded_metaschema",
  ...
}

I would think this is foolish, and might break some implementations (if using the $schema value directly as a lookup in a list of known metaschemas), but it doesn't seem to be strictly disallowed.

edit: I found https://json-schema.org/draft/2020-12/json-schema-core#section-8.1.2-6:

"The "$vocabulary" keyword SHOULD be used in the root schema of any schema document intended for use as a meta-schema. It MUST NOT appear in subschemas."

However, I don't think the $vocabulary keyword is strictly required in a metaschema (or perhaps this is the point that needs clarification?) -- as some metaschemas can be simply a combination of other schemas via an allOf.

Proposal

I can't see a good reason to allow this, so I would recommend making it explictly prohibited.

Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    • Status

      In Discussion

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions