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

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

mukesh-kumar3 created an issue. See original summary.

mukesh-kumar3’s picture

The 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.

mukesh-kumar3’s picture

Status: Active » Needs review
smustgrave’s picture

Title: Allow Regex constraints to contribute safe JSON Schema patterns » [PP-1] Allow Regex constraints to contribute safe JSON Schema patterns
Status: Needs review » Postponed

Seems this would be postponed on the other issue