Change record status: 
Project: 
Introduced in branch: 
main
Introduced in version: 
12.1.0
Description: 

The serializer's getJsonSchema() now describes lists (typed data).

Before, it returned just a $comment for a list, which matches any value in JSON Schema.

Example, a required list of names whose item is optional and has a label:

$definition = ListDataDefinition::create('string')
  ->setRequired(TRUE)
  ->setItemDefinition(DataDefinition::create('string')->setLabel(new TranslatableMarkup('Name')));
$data = \Drupal::typedDataManager()->create($definition);
$schema = \Drupal::service('serializer')->getJsonSchema($data, []);

$schema is then, encoded as JSON:

{"type":"array","items":{"oneOf":[{"type":"string"},{"type":"null"}],"title":"Name"},"minItems":1}

What each part comes from:

Validation also treats a required list of optional items that are all empty, like [null] or [[]], as NULL and rejects it. The schema accepts that list, because it has items.

Impacts: 
Module developers