/
ApiPlatformDescriber.php
47 lines (39 loc) · 1.96 KB
/
ApiPlatformDescriber.php
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
* This file is part of the NelmioApiDocBundle package.
*
* (c) Nelmio
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Nelmio\ApiDocBundle\Describer;
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
use ApiPlatform\Documentation\DocumentationInterface;
use ApiPlatform\OpenApi\OpenApi;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
final class ApiPlatformDescriber extends ExternalDocDescriber
{
public function __construct(object $documentation, NormalizerInterface $normalizer)
{
if (!$documentation instanceof DocumentationInterface && !$documentation instanceof OpenApi) {
throw new \InvalidArgumentException(sprintf('Argument 1 passed to %s() must be an instance of %s or %s. The documentation provided is an instance of %s.', __METHOD__, DocumentationInterface::class, OpenApi::class, get_class($documentation)));
}
if (!$normalizer->supportsNormalization($documentation, 'json')) {
throw new \InvalidArgumentException(sprintf('Argument 2 passed to %s() must implement %s and support normalization of %s. The normalizer provided is an instance of %s.', __METHOD__, NormalizerInterface::class, DocumentationInterface::class, get_class($normalizer)));
}
parent::__construct(function () use ($documentation, $normalizer) {
$documentation = (array) $normalizer->normalize(
$documentation,
null,
class_exists(DocumentationNormalizer::class) ? [DocumentationNormalizer::SPEC_VERSION => 3] : []
);
// TODO: remove this
// Temporary fix: zircote/swagger-php does no longer support 3.0.x with x > 0
unset($documentation['openapi']);
unset($documentation['basePath']);
unset($documentation['servers']);
return $documentation;
});
}
}