• 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

70.37
/src/OpenApi/Serializer/OpenApiNormalizer.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\OpenApi\Serializer;
15

16
use ApiPlatform\OpenApi\Model\Paths;
17
use ApiPlatform\OpenApi\OpenApi;
18
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
19
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21
use Symfony\Component\Serializer\Serializer;
22

23
/**
24
 * Generates an OpenAPI v3 specification.
25
 */
26
final class OpenApiNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
27
{
28
    public const FORMAT = 'json';
29
    private const EXTENSION_PROPERTIES_KEY = 'extensionProperties';
30

31
    public function __construct(private readonly NormalizerInterface $decorated)
32
    {
33
    }
54✔
34

35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function normalize(mixed $object, string $format = null, array $context = []): array
39
    {
40
        $pathsCallback = static fn ($innerObject): array => $innerObject instanceof Paths ? $innerObject->getPaths() : [];
6✔
41
        $context[AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS] = true;
6✔
42
        $context[AbstractObjectNormalizer::SKIP_NULL_VALUES] = true;
6✔
43
        $context[AbstractNormalizer::CALLBACKS] = [
6✔
44
            'paths' => $pathsCallback,
6✔
45
        ];
6✔
46

47
        return $this->recursiveClean($this->decorated->normalize($object, $format, $context));
6✔
48
    }
49

50
    private function recursiveClean(array $data): array
51
    {
52
        foreach ($data as $key => $value) {
6✔
53
            if (self::EXTENSION_PROPERTIES_KEY === $key) {
6✔
54
                foreach ($data[self::EXTENSION_PROPERTIES_KEY] as $extensionPropertyKey => $extensionPropertyValue) {
6✔
55
                    $data[$extensionPropertyKey] = $extensionPropertyValue;
6✔
56
                }
57
                continue;
6✔
58
            }
59

60
            if (\is_array($value)) {
6✔
61
                $data[$key] = $this->recursiveClean($value);
6✔
62
            }
63
        }
64

65
        unset($data[self::EXTENSION_PROPERTIES_KEY]);
6✔
66

67
        return $data;
6✔
68
    }
69

70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool
74
    {
75
        return self::FORMAT === $format && $data instanceof OpenApi;
6✔
76
    }
77

78
    public function getSupportedTypes($format): array
79
    {
80
        return self::FORMAT === $format ? [OpenApi::class => true] : [];
48✔
81
    }
82

83
    public function hasCacheableSupportsMethod(): bool
84
    {
85
        if (method_exists(Serializer::class, 'getSupportedTypes')) {
×
86
            trigger_deprecation(
×
87
                'api-platform/core',
×
88
                '3.1',
×
89
                'The "%s()" method is deprecated, use "getSupportedTypes()" instead.',
×
90
                __METHOD__
×
91
            );
×
92
        }
93

94
        return true;
×
95
    }
96
}
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