`format: uri` and `format: uri-reference` shape matching is too coarse

Created on 25 August 2025, 4 days ago

Overview

See https://opis.io/json-schema/2.x/formats.html#uri vs https://opis.io/json-schema/2.x/formats.html#uri-reference.

format: uri allows only absolute URLs, format: uri-reference allows both absolute and relative URLs.

However, \Drupal\Tests\experience_builder\Kernel\PropShapeToFieldInstanceTest::provider() shows we're not properly respecting this, because entity:file␝uri␞␟url evaluates to a relative URL, and is among the suggested DynamicPropSources for format: uri (absolute only), which will negatively impact 🌱 [META] Content templates Active :

        'REQUIRED, type=string&format=uri' => [
…
          'static prop source' => 'ℹ︎link␟url',
          'instances' => [
            'ℹ︎␜entity:file␝uri␞␟url',
            'ℹ︎␜entity:file␝uri␞␟value',
            'ℹ︎␜entity:media:baby_videos␝field_media_video_file␞␟entity␜␜entity:file␝uri␞␟url',
            'ℹ︎␜entity:media:baby_videos␝field_media_video_file␞␟entity␜␜entity:file␝uri␞␟value',
            'ℹ︎␜entity:media:vacation_videos␝field_media_video_file_1␞␟entity␜␜entity:file␝uri␞␟url',
            'ℹ︎␜entity:media:vacation_videos␝field_media_video_file_1␞␟entity␜␜entity:file␝uri␞␟value',
            'ℹ︎␜entity:node:foo␝field_silly_image␞␟entity␜␜entity:file␝uri␞␟url',
            'ℹ︎␜entity:node:foo␝field_silly_image␞␟entity␜␜entity:file␝uri␞␟value',
            'ℹ︎␜entity:node:foo␝field_silly_image␞␟src_with_alternate_widths',
          ],
…
        ],

Proposed resolution

Refine both

  1. (static prop sources)
          // TRICKY: Drupal core does not support RFC3987 aka IRIs, but it's a superset of RFC3986.
          // TRICKY: the `uri` and `iri` prop types will only pass validation with absolute paths, so we
          // instead use the link widget which is more permissive about the URI/IRI content.
          // @see \Drupal\Core\Field\Plugin\Field\FieldType\UriItem
          // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()
          static::UriReference, static::Uri, static::IriReference, static::Iri => new StorablePropShape(
            shape: $shape,
            fieldTypeProp: new FieldTypePropExpression('link', 'url'),
            // @see \Drupal\link\Plugin\Field\FieldType\LinkItem::defaultFieldSettings()
            fieldInstanceSettings: [
              // This shape only needs the URI, not a title.
              'title' => 0,
            ],
            fieldWidget: 'link_default',
          ),
    

    (for format: uri, use \Drupal\link\LinkItemInterface::LINK_GENERIC, and \Drupal\link\LinkItemInterface::LINK_INTERNAL for format: uri-reference)

  2. (dynamic prop sources)
          // TRICKY: Drupal core does not support RFC3987 aka IRIs, but it's a superset of RFC3986.
          static::UriReference, static::Uri, static::Iri, static::IriReference => new DataTypeShapeRequirement('PrimitiveType', [], UriInterface::class),
    

User interface changes

No more incorrect suggestions provided by 📌 Move `PropSourceEndpointTest` into new `XbConfigEntityHttpApiTest::testComponent()` Active .

🐛 Bug report
Status

Active

Version

1.0

Component

Shape matching

Created by

🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

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

Comments & Activities

Production build 0.71.5 2024