Overview

Broken out from #3507641: Allow components containing non-required images and no examples to be placed

\Drupal\experience_builder\ComponentMetadataRequirementsChecker::check() only checks for the presence of an examples[0], but it does not verify that it actually complies with the JSON Schema!

… because you'd reasonably expect that JSON Schema validates its examples, but … nope:

This keyword can be used to provide sample JSON values associated with a particular schema, for the purpose of illustrating usage. It is RECOMMENDED that these values be valid against the associated schema.

https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validati... 🧟‍♀️😭

So it's up to either Drupal core's SDC subsystem to strictly validate this (it doesn't), or up to XB.

Conclusion: XB must do this, since for XB it is critical.

(For those of you wondering: well, what if we'd use default instead? — ignoring the fact that the SDC subsystem doesn't use this at all, the same "recommended to be valid" statement is present there: https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validati... 😬)

Proposed resolution

  1. Add an SDC to the xb_test_sdc module with invalid example
  2. Update SingleDirectoryComponent::checkRequirements() to detect and disallow this
  3. Update \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testDiscovery() expectations

User interface changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

longwave created an issue. See original summary.

wim leers’s picture

Once #3509037: JavaScriptComponent config entities' `examples` and `enum` do not respect the prop's type lands, XB's code components will actually be at least mostly valid, so they will naturally pass validation here, too.

That's good, because we want to ensure that every valid code component actually works in XB. This issue is about ensuring that SDCs that can actually work in XB, are accepted.

Related problem spaces, but different things!

wim leers’s picture

Priority: Normal » Major
Issue tags: +stable blocker, +data integrity, +Configuration schema

Per #3509186-7: Code components: optional properties should not require examples, this would ensure that examples specified for code components would also be valid. So bumping priority.

wim leers’s picture

Component: Config management » Component sources
longwave’s picture

Assigned: Unassigned » longwave

Working on this.

longwave’s picture

Assigned: longwave » Unassigned
Status: Active » Needs review
penyaskito’s picture

Assigned: Unassigned » longwave
Status: Needs review » Needs work

One test is failing because of the order it expects the error messages 🤦🏽‍♂️

longwave’s picture

Assigned: longwave » Unassigned
Status: Needs work » Needs review

wim leers’s picture

Status: Needs review » Reviewed & tested by the community
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

wim leers’s picture

Issue status is not reflected everywhere correctly so … posting another comment 🤪

meghasharma’s picture

Assigned: Unassigned » meghasharma
Status: Fixed » Needs work
StatusFileSize
new480.14 KB

Reopening this issue because issue added a hard-requirement on JsonSchema/Validator.
Getting error while clearing cache.

meghasharma’s picture

Assigned: meghasharma » Unassigned
Status: Needs work » Fixed

Issue was from my end. Ran composer install properly and issue is resolved.
Thanks.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.