Skip to content

Commit 80959ad

Browse files
author
Alexis Thinardon
committed
Ability to disable entrypoint and /api/docs
1 parent e0dfbcd commit 80959ad

File tree

8 files changed

+32
-6
lines changed

8 files changed

+32
-6
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public function load(array $configs, ContainerBuilder $container)
143143
*/
144144
private function handleConfig(ContainerBuilder $container, array $config, array $formats, array $errorFormats)
145145
{
146+
$container->setParameter('api_platform.enable_entrypoint', $config['enable_entrypoint']);
147+
$container->setParameter('api_platform.enable_docs', $config['enable_docs']);
146148
$container->setParameter('api_platform.title', $config['title']);
147149
$container->setParameter('api_platform.description', $config['description']);
148150
$container->setParameter('api_platform.version', $config['version']);

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public function getConfigTreeBuilder()
9999
->end()
100100
->booleanNode('enable_swagger')->defaultValue(true)->info('Enable the Swagger documentation and export.')->end()
101101
->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger ui.')->end()
102+
->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
103+
->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()
102104

103105
->arrayNode('oauth')
104106
->canBeEnabled()

src/Bridge/Symfony/Bundle/Resources/config/routing/api.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@
1313
<requirement key="index">index</requirement>
1414
</route>
1515

16-
<route id="api_doc" path="/docs.{_format}">
17-
<default key="_controller">api_platform.action.documentation</default>
18-
<default key="_api_respond">1</default>
19-
<default key="_format" />
20-
</route>
21-
2216
</routes>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing
6+
http://symfony.com/schema/routing/routing-1.0.xsd">
7+
8+
<route id="api_doc" path="/docs.{_format}">
9+
<default key="_controller">api_platform.action.documentation</default>
10+
<default key="_api_respond">1</default>
11+
<default key="_format" />
12+
</route>
13+
14+
</routes>

src/Bridge/Symfony/Routing/ApiLoader.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ private function loadExternalFiles(RouteCollection $routeCollection)
146146
{
147147
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
148148

149+
if ($this->container->getParameter('api_platform.enable_entrypoint')) {
150+
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
151+
}
152+
153+
if ($this->container->getParameter('api_platform.enable_docs')) {
154+
$routeCollection->addCollection($this->fileLoader->load('docs.xml'));
155+
}
156+
149157
if ($this->graphqlEnabled) {
150158
$graphqlCollection = $this->fileLoader->load('graphql.xml');
151159
$graphqlCollection->addDefaults(['_graphql' => true]);

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ private function getPartialContainerBuilderProphecy($test = false)
396396
'api_platform.http_cache.shared_max_age' => null,
397397
'api_platform.http_cache.vary' => ['Accept'],
398398
'api_platform.http_cache.public' => null,
399+
'api_platform.enable_entrypoint' => true,
400+
'api_platform.enable_docs' => true,
399401
];
400402

401403
foreach ($parameters as $key => $value) {

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function testDefaultConfig()
7878
'enable_nelmio_api_doc' => false,
7979
'enable_swagger' => true,
8080
'enable_swagger_ui' => true,
81+
'enable_entrypoint' => true,
82+
'enable_docs' => true,
8183
'graphql' => [
8284
'enabled' => true,
8385
'graphiql' => [

tests/Bridge/Symfony/Routing/ApiLoaderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
210210
$containerProphecy->has($possibleArgument)->willReturn(true);
211211
}
212212
$containerProphecy->getParameter('api_platform.enable_swagger')->willReturn(true);
213+
$containerProphecy->getParameter('api_platform.enable_entrypoint')->willReturn(true);
214+
$containerProphecy->getParameter('api_platform.enable_docs')->willReturn(true);
213215

214216
$containerProphecy->has(Argument::type('string'))->willReturn(false);
215217

0 commit comments

Comments
 (0)