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

JsonSchemaProviderSerializerInterface::getJsonSchema() returns the JSON Schema for one object. Its documentation specified it also takes a class or interface name. That never worked: a class name throws a TypeError. The documentation now correctly describes it takes an object.

Passing anything other than an object is deprecated in drupal:12.1.0. In drupal:13.0.0, $object will be typed as object, and anything else will throw a TypeError.

An array of objects was the only non-object input that worked. The serializer normalized each item and returned a list of schemas. Call getJsonSchema() once per object instead.

Before

$schemas = $serializer->getJsonSchema([$item_a, $item_b], $context);

After

$schemas = array_map(
  fn (object $item): array => $serializer->getJsonSchema($item, $context),
  [$item_a, $item_b],
);
Impacts: 
Module developers