Change record status: 
Project: 
Introduced in branch: 
12.x, 11.x
Introduced in version: 
12.0.0, 11.4.0
Description: 

Single Directory Components can now use the references system of JSON schema with:

  • the $ref property to target a document with JSON schema definitions
  • a hash character (#) following by a JSON pointer notation to target a specific definition inside the document

The references URI can theoretically use any stream wrapper available in the PHP environment, but it is recommended to use the ones introduced in Drupal 11.3 (and limited to JSON files for now):

  • module://{module_id}/path/to/file.json#/path/to/definition
  • theme://{theme_id}/path/to/file.json#/path/to/definition

The convention is to have a schema.json file at the root of a module or theme.

Example

Reference in a SDC component:

name: Button
description: "Buttons allow the user to take actions or make choices."
props:
  type: object
  properties:
    label:
      title: Label
      type: string
    url:
      title: URL
      $ref: "module://foo/schema.json#/url"

schema.json file in foo module:

{
  "url": {
    "type": "string",
    "format": "iri-reference"
  }
}

To reduce its dependency to a module, a theme can copy the definitions from the module to its own schema.json file, because SDC API works with the references already resolved in a full schema.

Impacts: 
Module developers
Themers