|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Silverback API Components Bundle Project |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Daniel West <[email protected]> |
|
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 Silverback\ApiComponentsBundle\ApiPlatform\Serializer; |
|
15
|
|
|
|
|
16
|
|
|
use ApiPlatform\Documentation\Documentation; |
|
17
|
|
|
use ApiPlatform\Hydra\Serializer\DocumentationNormalizer; |
|
18
|
|
|
use Silverback\ApiComponentsBundle\OpenApi\OpenApiFactory; |
|
19
|
|
|
use Symfony\Component\Serializer\Exception\ExceptionInterface; |
|
20
|
|
|
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @author Daniel West <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
|
class VersionedDocumentationNormalizer implements NormalizerInterface |
|
26
|
|
|
{ |
|
27
|
|
|
private NormalizerInterface|DocumentationNormalizer $decorated; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(NormalizerInterface|DocumentationNormalizer $decorated) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->decorated = $decorated; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param Documentation $object |
|
36
|
|
|
* |
|
37
|
|
|
* @throws ExceptionInterface |
|
38
|
|
|
*/ |
|
39
|
|
|
public function normalize($object, string $format = null, array $context = []): array |
|
40
|
|
|
{ |
|
41
|
|
|
$doc = $this->decorated->normalize($object, $format, $context); |
|
42
|
|
|
if ('' !== $object->getVersion()) { |
|
43
|
|
|
$doc['info'] = ['version' => OpenApiFactory::getExtendedVersion($object->getVersion())]; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
return $doc; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function supportsNormalization($data, string $format = null, array $context = []): bool |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->decorated->supportsNormalization($data, $format, $context); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getSupportedTypes(?string $format): array |
|
55
|
|
|
{ |
|
56
|
|
|
return $this->decorated->getSupportedTypes($format); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.