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 ;
2020-05-28 13:19:11 +02:00
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer ;
2019-01-11 16:54:58 +01:00
use Symfony\Component\Serializer\Normalizer\NormalizerInterface ;
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
{
2019-01-11 16:54:58 +01:00
public function __construct ( Documentation $documentation , NormalizerInterface $normalizer )
2016-07-29 10:22:40 +02:00
{
2019-01-11 16:54:58 +01:00
if ( ! $normalizer -> supportsNormalization ( $documentation , 'json' )) {
2019-04-12 09:35:49 +02:00
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 , Documentation :: class , get_class ( $normalizer )));
2018-03-17 14:16:00 +01:00
}
2019-01-11 16:54:58 +01:00
parent :: __construct ( function () use ( $documentation , $normalizer ) {
2020-05-28 13:19:11 +02:00
$documentation = ( array ) $normalizer -> normalize (
$documentation ,
null ,
[ DocumentationNormalizer :: SPEC_VERSION => 3 ]
);
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
}
}