NelmioApiDocBundle/Describer/ApiPlatformDescriber.php

35 lines
1.3 KiB
PHP
Raw Normal View History

2016-07-29 10:22:40 +02:00
<?php
/*
2016-12-29 12:09:26 +01:00
* This file is part of the NelmioApiDocBundle package.
2016-07-29 10:22:40 +02:00
*
2016-12-29 12:09:26 +01:00
* (c) Nelmio
2016-07-29 10:22:40 +02:00
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
2016-12-29 12:09:26 +01:00
namespace Nelmio\ApiDocBundle\Describer;
2016-07-29 10:22:40 +02:00
use ApiPlatform\Core\Documentation\Documentation;
2018-03-17 14:16:00 +01:00
use ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer;
2016-11-18 22:16:53 +01:00
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
2017-07-05 15:41:53 +02:00
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
2016-07-29 10:22:40 +02:00
2016-11-30 15:04:53 +01:00
final class ApiPlatformDescriber extends ExternalDocDescriber
2016-07-29 10:22:40 +02:00
{
2018-03-17 14:16:00 +01:00
public function __construct(Documentation $documentation, $normalizer, UrlGeneratorInterface $urlGenerator)
2016-07-29 10:22:40 +02:00
{
2018-03-17 14:16:00 +01:00
if (!$normalizer instanceof ApiGatewayNormalizer && !$normalizer instanceof DocumentationNormalizer) {
throw new \InvalidArgumentException(sprintf('Argument 2 passed to %s() must be an instance of %s or %s, %s given.', __METHOD__, ApiGatewayNormalizer::class, DocumentationNormalizer::class, get_class($normalizer)));
2018-03-17 14:16:00 +01:00
}
2017-07-05 15:41:53 +02:00
parent::__construct(function () use ($documentation, $normalizer, $urlGenerator) {
2017-01-18 18:02:00 +01:00
$documentation = (array) $normalizer->normalize($documentation);
2017-07-05 15:41:53 +02:00
unset($documentation['basePath']);
2017-01-18 18:02:00 +01:00
return $documentation;
2017-07-05 15:41:53 +02:00
});
2016-07-29 10:22:40 +02:00
}
}