Problem/Motivation

#3620920 lets data definitions declare a default value through getDefault() and setDefault(). The value is descriptive metadata. The json_schema serialization format does not read it, so generated schemas omit the standard default keyword.

Steps to reproduce

N/A

Proposed resolution

Add an annotation helper to SchematicNormalizerHelperTrait. Call it from PrimitiveDataNormalizer and TypedDataNormalizer. These normalizers output the value in the format setValue() accepts, so the annotation matches the declared schema type. Normalizers which transform the value, such as the timestamp and datetime normalizers, do not annotate.

  • Values which cannot be represented in JSON are skipped, at any array depth.
  • \Stringable defaults are cast to strings.
  • JSON:API's FieldNormalizer removes an item-level default from the array schema of a multi-value field.

Remaining tasks

Review. Postponed on #3620920.

User interface changes

None

API changes

Two new protected methods on SchematicNormalizerHelperTrait. No changes to existing methods.

Data model changes

None

Generated with the help of an LLM.

Issue fork drupal-3623431

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 changed the visibility of the branch 3623431-emit-data-definition to hidden.

michaellander’s picture

michaellander’s picture

Component: typed data system » serialization.module