Skip to content

Ability to disable entrypoint and /api/docs #1580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public function load(array $configs, ContainerBuilder $container)
*/
private function handleConfig(ContainerBuilder $container, array $config, array $formats, array $errorFormats)
{
$container->setParameter('api_platform.enable_entrypoint', $config['enable_entrypoint']);
$container->setParameter('api_platform.enable_docs', $config['enable_docs']);
$container->setParameter('api_platform.title', $config['title']);
$container->setParameter('api_platform.description', $config['description']);
$container->setParameter('api_platform.version', $config['version']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ public function getConfigTreeBuilder()
->end()
->booleanNode('enable_swagger')->defaultValue(true)->info('Enable the Swagger documentation and export.')->end()
->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger ui.')->end()
->booleanNode('enable_entrypoint')->defaultTrue()->info('Enable the entrypoint')->end()
->booleanNode('enable_docs')->defaultTrue()->info('Enable the docs')->end()

->arrayNode('oauth')
->canBeEnabled()
Expand Down
2 changes: 2 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
<argument>%api_platform.resource_class_directories%</argument>
<argument type="service" id="api_platform.subresource_operation_factory" />
<argument>%api_platform.graphql.enabled%</argument>
<argument>%api_platform.enable_entrypoint%</argument>
<argument>%api_platform.enable_docs%</argument>

<tag name="routing.loader" />
</service>
Expand Down
6 changes: 0 additions & 6 deletions src/Bridge/Symfony/Bundle/Resources/config/routing/api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@
<requirement key="index">index</requirement>
</route>

<route id="api_doc" path="/docs.{_format}">
<default key="_controller">api_platform.action.documentation</default>
<default key="_api_respond">1</default>
<default key="_format" />
</route>

</routes>
14 changes: 14 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/routing/docs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>

<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="api_doc" path="/docs.{_format}">
<default key="_controller">api_platform.action.documentation</default>
<default key="_api_respond">1</default>
<default key="_format" />
</route>

</routes>
14 changes: 13 additions & 1 deletion src/Bridge/Symfony/Routing/ApiLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ final class ApiLoader extends Loader
private $resourceClassDirectories;
private $subresourceOperationFactory;
private $graphqlEnabled;
private $entrypointEnabled;
private $docsEnabled;

public function __construct(KernelInterface $kernel, ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, OperationPathResolverInterface $operationPathResolver, ContainerInterface $container, array $formats, array $resourceClassDirectories = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $graphqlEnabled = false)
public function __construct(KernelInterface $kernel, ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, OperationPathResolverInterface $operationPathResolver, ContainerInterface $container, array $formats, array $resourceClassDirectories = [], SubresourceOperationFactoryInterface $subresourceOperationFactory = null, bool $graphqlEnabled = false, bool $entrypointEnabled = true, bool $docsEnabled = true)
{
$this->fileLoader = new XmlFileLoader(new FileLocator($kernel->locateResource('@ApiPlatformBundle/Resources/config/routing')));
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
Expand All @@ -63,6 +65,8 @@ public function __construct(KernelInterface $kernel, ResourceNameCollectionFacto
$this->resourceClassDirectories = $resourceClassDirectories;
$this->subresourceOperationFactory = $subresourceOperationFactory;
$this->graphqlEnabled = $graphqlEnabled;
$this->entrypointEnabled = $entrypointEnabled;
$this->docsEnabled = $docsEnabled;
}

/**
Expand Down Expand Up @@ -146,6 +150,14 @@ private function loadExternalFiles(RouteCollection $routeCollection)
{
$routeCollection->addCollection($this->fileLoader->load('api.xml'));

if ($this->entrypointEnabled) {
$routeCollection->addCollection($this->fileLoader->load('api.xml'));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this add 2 times the api.xml file ? :o

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(looking at the line above)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks


if ($this->docsEnabled) {
$routeCollection->addCollection($this->fileLoader->load('docs.xml'));
}

if ($this->graphqlEnabled) {
$graphqlCollection = $this->fileLoader->load('graphql.xml');
$graphqlCollection->addDefaults(['_graphql' => true]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ private function getPartialContainerBuilderProphecy($test = false)
'api_platform.http_cache.shared_max_age' => null,
'api_platform.http_cache.vary' => ['Accept'],
'api_platform.http_cache.public' => null,
'api_platform.enable_entrypoint' => true,
'api_platform.enable_docs' => true,
];

foreach ($parameters as $key => $value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function testDefaultConfig()
'enable_nelmio_api_doc' => false,
'enable_swagger' => true,
'enable_swagger_ui' => true,
'enable_entrypoint' => true,
'enable_docs' => true,
'graphql' => [
'enabled' => true,
'graphiql' => [
Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Symfony/Routing/ApiLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta

$subresourceOperationFactory = new SubresourceOperationFactory($resourceMetadataFactory, $propertyNameCollectionFactoryProphecy->reveal(), $propertyMetadataFactoryProphecy->reveal(), new UnderscorePathSegmentNameGenerator());

$apiLoader = new ApiLoader($kernelProphecy->reveal(), $resourceNameCollectionFactoryProphecy->reveal(), $resourceMetadataFactory, $operationPathResolver, $containerProphecy->reveal(), ['jsonld' => ['application/ld+json']], [], $subresourceOperationFactory, false);
$apiLoader = new ApiLoader($kernelProphecy->reveal(), $resourceNameCollectionFactoryProphecy->reveal(), $resourceMetadataFactory, $operationPathResolver, $containerProphecy->reveal(), ['jsonld' => ['application/ld+json']], [], $subresourceOperationFactory, false, true, true);

return $apiLoader;
}
Expand Down