Problem/Motivation

#3620922 lets data definitions declare example values through getExamples() and setExamples(). The values are descriptive metadata. The json_schema serialization format does not read them, so generated schemas omit the standard examples keyword.

Steps to reproduce

N/A

Proposed resolution

Extend the annotation helper added in #3623431. PrimitiveDataNormalizer and TypedDataNormalizer emit the examples keyword. These normalizers output the value in the format setValue() accepts, so the annotation matches the declared schema type.

  • Examples which cannot be represented in JSON are dropped individually. The keyword is emitted when at least one example remains.
  • \Stringable examples are cast to strings. A NULL example is kept.
  • JSON:API's FieldNormalizer removes item-level examples from the array schema of a multi-value field.

Remaining tasks

Review. Postponed on #3620922 and #3623431.

User interface changes

None

API changes

SchematicNormalizerHelperTrait's protected casting method is renamed to serve both keywords. No other changes to existing methods.

Data model changes

None

Generated with the help of an LLM.

Issue fork drupal-3623432

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

michaellander created an issue. See original summary.

michaellander’s picture

michaellander’s picture

Component: typed data system » serialization.module
mglaman’s picture

Issue tags: +rosetta