Problem/Motivation
Follow-up to #3627330: Validation constraints do not contribute to the JSON Schema, requested by mglaman during review of MR !18061.
Regex constraints use PCRE patterns, while JSON Schema uses ECMA-262 patterns. Delimiters, modifiers, and anchoring need consideration before these constraints can safely contribute a pattern keyword.
Steps to reproduce
Create a string definition with a Regex constraint and generate its JSON Schema. The constraint's pattern is not represented.
Proposed resolution
Agree on a supported subset of patterns and implement the constraint interface proposed in #3627330: Validation constraints do not contribute to the JSON Schema. Evaluate whether Symfony's getHtmlPattern() can help without changing matching semantics.
Generated keywords must not reject values accepted by Drupal. Omit unsupported patterns and, initially, constraints with match: FALSE.
Remaining tasks
- Agree on conversion rules and unsupported cases.
- Implement keyword generation.
- Add tests for anchoring, modifiers, unsupported patterns, and nullable strings.
User interface changes
None.
Introduced terminology
None.
API changes
Supported Regex constraints would implement the interface established in #3627330: Validation constraints do not contribute to the JSON Schema.
Data model changes
None.
Release notes snippet
To be determined.
Issue fork drupal-3643475
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 #3
mukesh-kumar3 commentedThe Functional JavaScript job passed on retry without code changes. Local Regex unit tests (28 tests, 30 assertions), kernel tests (11 tests, 33 assertions), CSpell, PHPStan, and PHPCS also passed.
Comment #4
mukesh-kumar3 commentedComment #5
smustgrave commentedSeems this would be postponed on the other issue