Merge pull request #1172 from nelmio/api-platform

Fix Api-Platform support
This commit is contained in:
Guilhem N 2018-01-04 20:05:42 +01:00 committed by GitHub
commit 447f44e5a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 18 deletions

View File

@ -14,32 +14,15 @@ namespace Nelmio\ApiDocBundle\Describer;
use ApiPlatform\Core\Documentation\Documentation;
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\RequestContext;
final class ApiPlatformDescriber extends ExternalDocDescriber
{
public function __construct(Documentation $documentation, DocumentationNormalizer $normalizer, UrlGeneratorInterface $urlGenerator)
{
parent::__construct(function () use ($documentation, $normalizer, $urlGenerator) {
$paths = [];
$baseContext = $urlGenerator->getContext();
$urlGenerator->setContext(new RequestContext());
try {
$basePath = $urlGenerator->generate('api_entrypoint');
} finally {
$urlGenerator->setContext($baseContext);
}
$documentation = (array) $normalizer->normalize($documentation);
unset($documentation['basePath']);
foreach ($documentation['paths'] as $path => $value) {
$paths['/'.ltrim($basePath.'/'.ltrim($path, '/'), '/')] = $value;
}
$documentation['paths'] = $paths;
return $documentation;
});
}

View File

@ -37,9 +37,10 @@
"symfony/stopwatch": "^3.4|^4.0",
"sensio/framework-extra-bundle": "^3.0",
"doctrine/annotations": "^1.2",
"doctrine/common": "^2.4",
"phpdocumentor/reflection-docblock": "^3.1",
"api-platform/core": "^2.0.3",
"api-platform/core": "^2.1.0",
"friendsofsymfony/rest-bundle": "^2.0",
"jms/serializer-bundle": "^2.0"
},