• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 5650127293

pending completion
5650127293

push

github

web-flow
fix: don't implement deprecated CacheableSupportsMethodInterface with Symfony 6.3+ (#5696)

* fix: don't implement deprecated CacheableSupportsMethodInterface

* fix: a check, and add tests

* fix ApiGatewayNormalizerTest

* more fixes

* fix more tests

* fix lowest

* only trigger the deprecation for Symfony 6.3

167 of 167 new or added lines in 23 files covered. (100.0%)

10865 of 18368 relevant lines covered (59.15%)

19.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.69
/src/Hydra/Serializer/DocumentationNormalizer.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Hydra\Serializer;
15

16
use ApiPlatform\Api\ResourceClassResolverInterface;
17
use ApiPlatform\Api\UrlGeneratorInterface;
18
use ApiPlatform\Documentation\Documentation;
19
use ApiPlatform\JsonLd\ContextBuilderInterface;
20
use ApiPlatform\Metadata\ApiProperty;
21
use ApiPlatform\Metadata\ApiResource;
22
use ApiPlatform\Metadata\CollectionOperationInterface;
23
use ApiPlatform\Metadata\HttpOperation;
24
use ApiPlatform\Metadata\Operation;
25
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
26
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
27
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
28
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
29
use ApiPlatform\Serializer\CacheableSupportsMethodInterface;
30
use Symfony\Component\PropertyInfo\Type;
31
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
32
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
33
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
34
use Symfony\Component\Serializer\Serializer;
35

36
/**
37
 * Creates a machine readable Hydra API documentation.
38
 *
39
 * @author Kévin Dunglas <dunglas@gmail.com>
40
 */
41
final class DocumentationNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
42
{
43
    public const FORMAT = 'jsonld';
44

45
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly UrlGeneratorInterface $urlGenerator, private readonly ?NameConverterInterface $nameConverter = null)
46
    {
47
    }
58✔
48

49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function normalize(mixed $object, string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
53
    {
54
        $classes = [];
4✔
55
        $entrypointProperties = [];
4✔
56

57
        foreach ($object->getResourceNameCollection() as $resourceClass) {
4✔
58
            $resourceMetadataCollection = $this->resourceMetadataFactory->create($resourceClass);
4✔
59

60
            $resourceMetadata = $resourceMetadataCollection[0];
4✔
61
            $shortName = $resourceMetadata->getShortName();
4✔
62
            $prefixedShortName = $resourceMetadata->getTypes()[0] ?? "#$shortName";
4✔
63
            $this->populateEntrypointProperties($resourceMetadata, $shortName, $prefixedShortName, $entrypointProperties, $resourceMetadataCollection);
4✔
64
            $classes[] = $this->getClass($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context, $resourceMetadataCollection);
4✔
65
        }
66

67
        return $this->computeDoc($object, $this->getClasses($entrypointProperties, $classes));
4✔
68
    }
69

70
    /**
71
     * Populates entrypoint properties.
72
     */
73
    private function populateEntrypointProperties(ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array &$entrypointProperties, ResourceMetadataCollection $resourceMetadataCollection = null): void
74
    {
75
        $hydraCollectionOperations = $this->getHydraOperations(true, $resourceMetadataCollection);
4✔
76
        if (empty($hydraCollectionOperations)) {
4✔
77
            return;
×
78
        }
79

80
        $entrypointProperty = [
4✔
81
            '@type' => 'hydra:SupportedProperty',
4✔
82
            'hydra:property' => [
4✔
83
                '@id' => sprintf('#Entrypoint/%s', lcfirst($shortName)),
4✔
84
                '@type' => 'hydra:Link',
4✔
85
                'domain' => '#Entrypoint',
4✔
86
                'rdfs:label' => "The collection of $shortName resources",
4✔
87
                'rdfs:range' => [
4✔
88
                    ['@id' => 'hydra:Collection'],
4✔
89
                    [
4✔
90
                        'owl:equivalentClass' => [
4✔
91
                            'owl:onProperty' => ['@id' => 'hydra:member'],
4✔
92
                            'owl:allValuesFrom' => ['@id' => $prefixedShortName],
4✔
93
                        ],
4✔
94
                    ],
4✔
95
                ],
4✔
96
                'hydra:supportedOperation' => $hydraCollectionOperations,
4✔
97
            ],
4✔
98
            'hydra:title' => "The collection of $shortName resources",
4✔
99
            'hydra:readable' => true,
4✔
100
            'hydra:writeable' => false,
4✔
101
        ];
4✔
102

103
        if ($resourceMetadata->getDeprecationReason()) {
4✔
104
            $entrypointProperty['owl:deprecated'] = true;
×
105
        }
106

107
        $entrypointProperties[] = $entrypointProperty;
4✔
108
    }
109

110
    /**
111
     * Gets a Hydra class.
112
     */
113
    private function getClass(string $resourceClass, ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array $context, ResourceMetadataCollection $resourceMetadataCollection = null): array
114
    {
115
        $description = $resourceMetadata->getDescription();
4✔
116
        $isDeprecated = $resourceMetadata->getDeprecationReason();
4✔
117

118
        $class = [
4✔
119
            '@id' => $prefixedShortName,
4✔
120
            '@type' => 'hydra:Class',
4✔
121
            'rdfs:label' => $shortName,
4✔
122
            'hydra:title' => $shortName,
4✔
123
            'hydra:supportedProperty' => $this->getHydraProperties($resourceClass, $resourceMetadata, $shortName, $prefixedShortName, $context),
4✔
124
            'hydra:supportedOperation' => $this->getHydraOperations(false, $resourceMetadataCollection),
4✔
125
        ];
4✔
126

127
        if (null !== $description) {
4✔
128
            $class['hydra:description'] = $description;
4✔
129
        }
130

131
        if ($isDeprecated) {
4✔
132
            $class['owl:deprecated'] = true;
×
133
        }
134

135
        return $class;
4✔
136
    }
137

138
    /**
139
     * Creates context for property metatata factories.
140
     */
141
    private function getPropertyMetadataFactoryContext(ApiResource $resourceMetadata): array
142
    {
143
        $normalizationGroups = $resourceMetadata->getNormalizationContext()[AbstractNormalizer::GROUPS] ?? null;
4✔
144
        $denormalizationGroups = $resourceMetadata->getDenormalizationContext()[AbstractNormalizer::GROUPS] ?? null;
4✔
145
        $propertyContext = [
4✔
146
            'normalization_groups' => $normalizationGroups,
4✔
147
            'denormalization_groups' => $denormalizationGroups,
4✔
148
        ];
4✔
149
        $propertyNameContext = [];
4✔
150

151
        if ($normalizationGroups) {
4✔
152
            $propertyNameContext['serializer_groups'] = $normalizationGroups;
×
153
        }
154

155
        if (!$denormalizationGroups) {
4✔
156
            return [$propertyNameContext, $propertyContext];
4✔
157
        }
158

159
        if (!isset($propertyNameContext['serializer_groups'])) {
×
160
            $propertyNameContext['serializer_groups'] = $denormalizationGroups;
×
161

162
            return [$propertyNameContext, $propertyContext];
×
163
        }
164

165
        foreach ($denormalizationGroups as $group) {
×
166
            $propertyNameContext['serializer_groups'][] = $group;
×
167
        }
168

169
        return [$propertyNameContext, $propertyContext];
×
170
    }
171

172
    /**
173
     * Gets Hydra properties.
174
     */
175
    private function getHydraProperties(string $resourceClass, ApiResource $resourceMetadata, string $shortName, string $prefixedShortName, array $context): array
176
    {
177
        $classes = [];
4✔
178

179
        $classes[$resourceClass] = true;
4✔
180
        foreach ($resourceMetadata->getOperations() as $operation) {
4✔
181
            /** @var Operation $operation */
182
            if (!$operation instanceof CollectionOperationInterface) {
4✔
183
                continue;
4✔
184
            }
185

186
            $inputMetadata = $operation->getInput();
4✔
187
            if (null !== $inputClass = $inputMetadata['class'] ?? null) {
4✔
188
                $classes[$inputClass] = true;
2✔
189
            }
190

191
            $outputMetadata = $operation->getOutput();
4✔
192
            if (null !== $outputClass = $outputMetadata['class'] ?? null) {
4✔
193
                $classes[$outputClass] = true;
2✔
194
            }
195
        }
196

197
        /** @var string[] $classes */
198
        $classes = array_keys($classes);
4✔
199
        $properties = [];
4✔
200
        [$propertyNameContext, $propertyContext] = $this->getPropertyMetadataFactoryContext($resourceMetadata);
4✔
201

202
        foreach ($classes as $class) {
4✔
203
            foreach ($this->propertyNameCollectionFactory->create($class, $propertyNameContext) as $propertyName) {
4✔
204
                $propertyMetadata = $this->propertyMetadataFactory->create($class, $propertyName, $propertyContext);
4✔
205

206
                if (true === $propertyMetadata->isIdentifier() && false === $propertyMetadata->isWritable()) {
4✔
207
                    continue;
×
208
                }
209

210
                if ($this->nameConverter) {
4✔
211
                    $propertyName = $this->nameConverter->normalize($propertyName, $class, self::FORMAT, $context);
2✔
212
                }
213

214
                $properties[] = $this->getProperty($propertyMetadata, $propertyName, $prefixedShortName, $shortName);
4✔
215
            }
216
        }
217

218
        return $properties;
4✔
219
    }
220

221
    /**
222
     * Gets Hydra operations.
223
     */
224
    private function getHydraOperations(bool $collection, ResourceMetadataCollection $resourceMetadataCollection = null): array
225
    {
226
        $hydraOperations = [];
4✔
227
        foreach ($resourceMetadataCollection as $resourceMetadata) {
4✔
228
            foreach ($resourceMetadata->getOperations() as $operation) {
4✔
229
                if ((HttpOperation::METHOD_POST === $operation->getMethod() || $operation instanceof CollectionOperationInterface) !== $collection) {
4✔
230
                    continue;
4✔
231
                }
232

233
                $hydraOperations[] = $this->getHydraOperation($operation, $operation->getTypes()[0] ?? "#{$operation->getShortName()}");
4✔
234
            }
235
        }
236

237
        return $hydraOperations;
4✔
238
    }
239

240
    /**
241
     * Gets and populates if applicable a Hydra operation.
242
     */
243
    private function getHydraOperation(HttpOperation $operation, string $prefixedShortName): array
244
    {
245
        $method = $operation->getMethod() ?: HttpOperation::METHOD_GET;
4✔
246

247
        $hydraOperation = $operation->getHydraContext() ?? [];
4✔
248
        if ($operation->getDeprecationReason()) {
4✔
249
            $hydraOperation['owl:deprecated'] = true;
×
250
        }
251

252
        $shortName = $operation->getShortName();
4✔
253
        $inputMetadata = $operation->getInput() ?? [];
4✔
254
        $outputMetadata = $operation->getOutput() ?? [];
4✔
255

256
        $inputClass = \array_key_exists('class', $inputMetadata) ? $inputMetadata['class'] : false;
4✔
257
        $outputClass = \array_key_exists('class', $outputMetadata) ? $outputMetadata['class'] : false;
4✔
258

259
        if ('GET' === $method && $operation instanceof CollectionOperationInterface) {
4✔
260
            $hydraOperation += [
4✔
261
                '@type' => ['hydra:Operation', 'schema:FindAction'],
4✔
262
                'hydra:title' => "Retrieves the collection of $shortName resources.",
4✔
263
                'returns' => null === $outputClass ? 'owl:Nothing' : 'hydra:Collection',
4✔
264
            ];
4✔
265
        } elseif ('GET' === $method) {
4✔
266
            $hydraOperation += [
4✔
267
                '@type' => ['hydra:Operation', 'schema:FindAction'],
4✔
268
                'hydra:title' => "Retrieves a $shortName resource.",
4✔
269
                'returns' => null === $outputClass ? 'owl:Nothing' : $prefixedShortName,
4✔
270
            ];
4✔
271
        } elseif ('PATCH' === $method) {
4✔
272
            $hydraOperation += [
×
273
                '@type' => 'hydra:Operation',
×
274
                'hydra:title' => "Updates the $shortName resource.",
×
275
                'returns' => null === $outputClass ? 'owl:Nothing' : $prefixedShortName,
×
276
                'expects' => null === $inputClass ? 'owl:Nothing' : $prefixedShortName,
×
277
            ];
×
278
        } elseif ('POST' === $method) {
4✔
279
            $hydraOperation += [
4✔
280
                '@type' => ['hydra:Operation', 'schema:CreateAction'],
4✔
281
                'hydra:title' => "Creates a $shortName resource.",
4✔
282
                'returns' => null === $outputClass ? 'owl:Nothing' : $prefixedShortName,
4✔
283
                'expects' => null === $inputClass ? 'owl:Nothing' : $prefixedShortName,
4✔
284
            ];
4✔
285
        } elseif ('PUT' === $method) {
4✔
286
            $hydraOperation += [
4✔
287
                '@type' => ['hydra:Operation', 'schema:ReplaceAction'],
4✔
288
                'hydra:title' => "Replaces the $shortName resource.",
4✔
289
                'returns' => null === $outputClass ? 'owl:Nothing' : $prefixedShortName,
4✔
290
                'expects' => null === $inputClass ? 'owl:Nothing' : $prefixedShortName,
4✔
291
            ];
4✔
292
        } elseif ('DELETE' === $method) {
×
293
            $hydraOperation += [
×
294
                '@type' => ['hydra:Operation', 'schema:DeleteAction'],
×
295
                'hydra:title' => "Deletes the $shortName resource.",
×
296
                'returns' => 'owl:Nothing',
×
297
            ];
×
298
        }
299

300
        $hydraOperation['hydra:method'] ?? $hydraOperation['hydra:method'] = $method;
4✔
301

302
        if (!isset($hydraOperation['rdfs:label']) && isset($hydraOperation['hydra:title'])) {
4✔
303
            $hydraOperation['rdfs:label'] = $hydraOperation['hydra:title'];
4✔
304
        }
305

306
        ksort($hydraOperation);
4✔
307

308
        return $hydraOperation;
4✔
309
    }
310

311
    /**
312
     * Gets the range of the property.
313
     */
314
    private function getRange(ApiProperty $propertyMetadata): ?string
315
    {
316
        $jsonldContext = $propertyMetadata->getJsonldContext();
4✔
317

318
        if (isset($jsonldContext['@type'])) {
4✔
319
            return $jsonldContext['@type'];
2✔
320
        }
321

322
        // TODO: 3.0 support multiple types, default value of types will be [] instead of null
323
        $type = $propertyMetadata->getBuiltinTypes()[0] ?? null;
4✔
324
        if (null === $type) {
4✔
325
            return null;
2✔
326
        }
327

328
        if ($type->isCollection() && null !== $collectionType = $type->getCollectionValueTypes()[0] ?? null) {
4✔
329
            $type = $collectionType;
2✔
330
        }
331

332
        switch ($type->getBuiltinType()) {
4✔
333
            case Type::BUILTIN_TYPE_STRING:
334
                return 'xmls:string';
4✔
335
            case Type::BUILTIN_TYPE_INT:
336
                return 'xmls:integer';
×
337
            case Type::BUILTIN_TYPE_FLOAT:
338
                return 'xmls:decimal';
×
339
            case Type::BUILTIN_TYPE_BOOL:
340
                return 'xmls:boolean';
×
341
            case Type::BUILTIN_TYPE_OBJECT:
342
                if (null === $className = $type->getClassName()) {
2✔
343
                    return null;
×
344
                }
345

346
                if (is_a($className, \DateTimeInterface::class, true)) {
2✔
347
                    return 'xmls:dateTime';
×
348
                }
349

350
                if ($this->resourceClassResolver->isResourceClass($className)) {
2✔
351
                    $resourceMetadata = $this->resourceMetadataFactory->create($className);
2✔
352
                    $operation = $resourceMetadata->getOperation();
2✔
353

354
                    if (!$operation instanceof HttpOperation) {
2✔
355
                        return "#{$operation->getShortName()}";
×
356
                    }
357

358
                    return $operation->getTypes()[0] ?? "#{$operation->getShortName()}";
2✔
359
                }
360
        }
361

362
        return null;
×
363
    }
364

365
    /**
366
     * Builds the classes array.
367
     */
368
    private function getClasses(array $entrypointProperties, array $classes): array
369
    {
370
        $classes[] = [
4✔
371
            '@id' => '#Entrypoint',
4✔
372
            '@type' => 'hydra:Class',
4✔
373
            'hydra:title' => 'The API entrypoint',
4✔
374
            'hydra:supportedProperty' => $entrypointProperties,
4✔
375
            'hydra:supportedOperation' => [
4✔
376
                '@type' => 'hydra:Operation',
4✔
377
                'hydra:method' => 'GET',
4✔
378
                'rdfs:label' => 'The API entrypoint.',
4✔
379
                'returns' => '#EntryPoint',
4✔
380
            ],
4✔
381
        ];
4✔
382

383
        // Constraint violation
384
        $classes[] = [
4✔
385
            '@id' => '#ConstraintViolation',
4✔
386
            '@type' => 'hydra:Class',
4✔
387
            'hydra:title' => 'A constraint violation',
4✔
388
            'hydra:supportedProperty' => [
4✔
389
                [
4✔
390
                    '@type' => 'hydra:SupportedProperty',
4✔
391
                    'hydra:property' => [
4✔
392
                        '@id' => '#ConstraintViolation/propertyPath',
4✔
393
                        '@type' => 'rdf:Property',
4✔
394
                        'rdfs:label' => 'propertyPath',
4✔
395
                        'domain' => '#ConstraintViolation',
4✔
396
                        'range' => 'xmls:string',
4✔
397
                    ],
4✔
398
                    'hydra:title' => 'propertyPath',
4✔
399
                    'hydra:description' => 'The property path of the violation',
4✔
400
                    'hydra:readable' => true,
4✔
401
                    'hydra:writeable' => false,
4✔
402
                ],
4✔
403
                [
4✔
404
                    '@type' => 'hydra:SupportedProperty',
4✔
405
                    'hydra:property' => [
4✔
406
                        '@id' => '#ConstraintViolation/message',
4✔
407
                        '@type' => 'rdf:Property',
4✔
408
                        'rdfs:label' => 'message',
4✔
409
                        'domain' => '#ConstraintViolation',
4✔
410
                        'range' => 'xmls:string',
4✔
411
                    ],
4✔
412
                    'hydra:title' => 'message',
4✔
413
                    'hydra:description' => 'The message associated with the violation',
4✔
414
                    'hydra:readable' => true,
4✔
415
                    'hydra:writeable' => false,
4✔
416
                ],
4✔
417
            ],
4✔
418
        ];
4✔
419

420
        // Constraint violation list
421
        $classes[] = [
4✔
422
            '@id' => '#ConstraintViolationList',
4✔
423
            '@type' => 'hydra:Class',
4✔
424
            'subClassOf' => 'hydra:Error',
4✔
425
            'hydra:title' => 'A constraint violation list',
4✔
426
            'hydra:supportedProperty' => [
4✔
427
                [
4✔
428
                    '@type' => 'hydra:SupportedProperty',
4✔
429
                    'hydra:property' => [
4✔
430
                        '@id' => '#ConstraintViolationList/violations',
4✔
431
                        '@type' => 'rdf:Property',
4✔
432
                        'rdfs:label' => 'violations',
4✔
433
                        'domain' => '#ConstraintViolationList',
4✔
434
                        'range' => '#ConstraintViolation',
4✔
435
                    ],
4✔
436
                    'hydra:title' => 'violations',
4✔
437
                    'hydra:description' => 'The violations',
4✔
438
                    'hydra:readable' => true,
4✔
439
                    'hydra:writeable' => false,
4✔
440
                ],
4✔
441
            ],
4✔
442
        ];
4✔
443

444
        return $classes;
4✔
445
    }
446

447
    /**
448
     * Gets a property definition.
449
     */
450
    private function getProperty(ApiProperty $propertyMetadata, string $propertyName, string $prefixedShortName, string $shortName): array
451
    {
452
        if ($iri = $propertyMetadata->getIris()) {
4✔
453
            $iri = 1 === (is_countable($iri) ? \count($iri) : 0) ? $iri[0] : $iri;
2✔
454
        }
455

456
        if (!isset($iri)) {
4✔
457
            $iri = "#$shortName/$propertyName";
4✔
458
        }
459

460
        $propertyData = [
4✔
461
            '@id' => $iri,
4✔
462
            '@type' => false === $propertyMetadata->isReadableLink() ? 'hydra:Link' : 'rdf:Property',
4✔
463
            'rdfs:label' => $propertyName,
4✔
464
            'domain' => $prefixedShortName,
4✔
465
        ];
4✔
466

467
        // TODO: 3.0 support multiple types, default value of types will be [] instead of null
468
        $type = $propertyMetadata->getBuiltinTypes()[0] ?? null;
4✔
469

470
        if (null !== $type && !$type->isCollection() && (null !== $className = $type->getClassName()) && $this->resourceClassResolver->isResourceClass($className)) {
4✔
471
            $propertyData['owl:maxCardinality'] = 1;
×
472
        }
473

474
        $property = [
4✔
475
            '@type' => 'hydra:SupportedProperty',
4✔
476
            'hydra:property' => $propertyData,
4✔
477
            'hydra:title' => $propertyName,
4✔
478
            'hydra:required' => $propertyMetadata->isRequired(),
4✔
479
            'hydra:readable' => $propertyMetadata->isReadable(),
4✔
480
            'hydra:writeable' => $propertyMetadata->isWritable() || $propertyMetadata->isInitializable(),
4✔
481
        ];
4✔
482

483
        if (null !== $range = $this->getRange($propertyMetadata)) {
4✔
484
            $property['hydra:property']['range'] = $range;
4✔
485
        }
486

487
        if (null !== $description = $propertyMetadata->getDescription()) {
4✔
488
            $property['hydra:description'] = $description;
4✔
489
        }
490

491
        if ($deprecationReason = $propertyMetadata->getDeprecationReason()) {
4✔
492
            $property['owl:deprecated'] = true;
×
493
        }
494

495
        return $property;
4✔
496
    }
497

498
    /**
499
     * Computes the documentation.
500
     */
501
    private function computeDoc(Documentation $object, array $classes): array
502
    {
503
        $doc = ['@context' => $this->getContext(), '@id' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT]), '@type' => 'hydra:ApiDocumentation'];
4✔
504

505
        if ('' !== $object->getTitle()) {
4✔
506
            $doc['hydra:title'] = $object->getTitle();
4✔
507
        }
508

509
        if ('' !== $object->getDescription()) {
4✔
510
            $doc['hydra:description'] = $object->getDescription();
4✔
511
        }
512

513
        $doc['hydra:entrypoint'] = $this->urlGenerator->generate('api_entrypoint');
4✔
514
        $doc['hydra:supportedClass'] = $classes;
4✔
515

516
        return $doc;
4✔
517
    }
518

519
    /**
520
     * Builds the JSON-LD context for the API documentation.
521
     */
522
    private function getContext(): array
523
    {
524
        return [
4✔
525
            '@vocab' => $this->urlGenerator->generate('api_doc', ['_format' => self::FORMAT], UrlGeneratorInterface::ABS_URL).'#',
4✔
526
            'hydra' => ContextBuilderInterface::HYDRA_NS,
4✔
527
            'rdf' => ContextBuilderInterface::RDF_NS,
4✔
528
            'rdfs' => ContextBuilderInterface::RDFS_NS,
4✔
529
            'xmls' => ContextBuilderInterface::XML_NS,
4✔
530
            'owl' => ContextBuilderInterface::OWL_NS,
4✔
531
            'schema' => ContextBuilderInterface::SCHEMA_ORG_NS,
4✔
532
            'domain' => ['@id' => 'rdfs:domain', '@type' => '@id'],
4✔
533
            'range' => ['@id' => 'rdfs:range', '@type' => '@id'],
4✔
534
            'subClassOf' => ['@id' => 'rdfs:subClassOf', '@type' => '@id'],
4✔
535
            'expects' => ['@id' => 'hydra:expects', '@type' => '@id'],
4✔
536
            'returns' => ['@id' => 'hydra:returns', '@type' => '@id'],
4✔
537
        ];
4✔
538
    }
539

540
    /**
541
     * {@inheritdoc}
542
     */
543
    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
544
    {
545
        return self::FORMAT === $format && $data instanceof Documentation;
2✔
546
    }
547

548
    public function getSupportedTypes($format): array
549
    {
550
        return self::FORMAT === $format ? [Documentation::class => true] : [];
44✔
551
    }
552

553
    public function hasCacheableSupportsMethod(): bool
554
    {
555
        if (method_exists(Serializer::class, 'getSupportedTypes')) {
×
556
            trigger_deprecation(
×
557
                'api-platform/core',
×
558
                '3.1',
×
559
                'The "%s()" method is deprecated, use "getSupportedTypes()" instead.',
×
560
                __METHOD__
×
561
            );
×
562
        }
563

564
        return true;
×
565
    }
566
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc