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
— 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... 😬)default instead?
Proposed resolution
- Add an SDC to the
xb_test_sdcmodule with invalid example - Update
SingleDirectoryComponent::checkRequirements()to detect and disallow this - Update
\Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testDiscovery()expectations
User interface changes
None.
| Comment | File | Size | Author |
|---|
Issue fork experience_builder-3508725
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
Comment #2
wim leersOnce #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!
Comment #3
wim leersPer #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.
Comment #4
wim leersComment #5
wim leersComment #6
longwaveWorking on this.
Comment #8
longwaveComment #9
penyaskitoOne test is failing because of the order it expects the error messages 🤦🏽♂️
Comment #10
longwaveComment #12
wim leersComment #13
wim leersComment #15
wim leersIssue status is not reflected everywhere correctly so … posting another comment 🤪
Comment #16
meghasharma commentedReopening this issue because issue added a hard-requirement on JsonSchema/Validator.
Getting error while clearing cache.
Comment #17
meghasharma commentedIssue was from my end. Ran composer install properly and issue is resolved.
Thanks.