summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/serialization/src/Serializer/JsonSchemaProviderSerializerTrait.php
blob: a239460f4cb0914cadba939212263e66e1576a65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php

declare(strict_types=1);

namespace Drupal\serialization\Serializer;

use Drupal\serialization\Normalizer\SchematicNormalizerFallbackTrait;
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;

/**
 * Trait for normalizing the JSON schema.
 */
trait JsonSchemaProviderSerializerTrait {

  use SchematicNormalizerFallbackTrait;

  /**
   * {@inheritdoc}
   */
  public function getJsonSchema(mixed $object, array $context): array {
    try {
      $normalizer_schema = $this->normalize($object, 'json_schema', $context);
    }
    catch (NotNormalizableValueException) {
      $normalizer_schema = ['$comment' => static::generateNoSchemaAvailableMessage($object)];
    }
    return $normalizer_schema;
  }

}