Don't break other JSON Schema references

Created on 3 October 2025, 18 days ago

Overview

Canvas is using JSON Schema references. Example:
{$ref: 'json-schema-definitions://experience_builder.module/image'}

They are resolved by JsonSchemaDefinitionsStreamwrapper which is looking fine:

  Drupal\canvas\JsonSchemaDefinitionsStreamwrapper:
    public: true
    tags:
      - { name: stream_wrapper, scheme: json-schema-definitions }

So it seems just letting the StreamWrapper do its job is enough. However, at a few places in Canvas code, the stream wrapper is replaced/overriden by a direct call to json_decode().

AdapterBase::resolveSchemaReferences():

    if (isset($schema['$ref'])) {
      $schema = json_decode(file_get_contents($schema['$ref']) ?: '{}', TRUE);
    }

PropShape::resolveSchemaReferences():

    if (isset($schema['$ref'])) {
      $schema = json_decode(file_get_contents($schema['$ref']) ?: '{}', TRUE);
    }

JsonSchemaFieldInstanceMatcher::resolveSchemaReferences():

    if (isset($schema['$ref'])) {
      $schema = json_decode(file_get_contents($schema['$ref']) ?: '{}', TRUE);
    }

JsonSchemaObject::__construct():

    $schema = \json_decode(\file_get_contents($ref) ?: '{}', TRUE, \JSON_THROW_ON_ERROR);

and:

      if (\array_key_exists('$ref', $detail)) {
        $prop_schema = \json_decode(\file_get_contents($detail['$ref']) ?: '{}', TRUE, \JSON_THROW_ON_ERROR);

Maybe more...

This is error prone for Canvas and this is breaking all other uses of JSON Schema references in SDC. The ones from UI Patterns , the module I am maintaining, but also any other a Drupaler may use (including the ones defined outside the Drupal ecosystem).

Proposed resolution

My knowledge of Canvas is not deep enough to propose a fix for the root causes (see "Follow-up"), but let's try a quick "damage control" fix:

  1. Some little changes to not block other SDC plugin managers decorators (necessary to test concurrent reference resolvers).
  2. Add a reference resolver in the component plugin manager (without resolving json-schema-definitions:// until 🐛 References must not be required to guess props' JSON schema Active is OK)
  3. Limit json_decode(file_get_contents($schema['$ref']) execution to json-schema-definitions:// URI, to prevent the break of non Canvas JSON Schema references.

Follow-ups

Once this first fix merged:

  1. The root cause of "Don't block other SDC plugin managers decorators": It seems Canvas's ComponentPluginManager decorator is doing inheritance over composition, so it doesn't chain properly. Issue to be created.
  2. The root cause of the JSON schema issue: Remove all json_decode(file_get_contents($schema['$ref']). JsonSchemaDefinitionsStreamwrapper is already executing file_get_contents and all parts of the Canvas app must work on the resolved JSON schema returned by this service.
  3. A related, but orthogonal, issue about JSON Schema references: 🐛 References must not be required to guess props' JSON schema Active

User interface changes

can
None.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇫🇷France pdureau Paris

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024