Skip to content
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 @@ -141,7 +141,13 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array
}

$loader->load('swagger.xml');
$container->setParameter('api_platform.enable_swagger', (string) $config['enable_swagger']);

if ($config['enable_swagger_ui']) {
$loader->load('swagger-ui.xml');
$container->setParameter('api_platform.enable_swagger_ui', $config['enable_swagger_ui']);
Copy link
Member

Choose a reason for hiding this comment

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

And if $config['enable_swagger_ui'] is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not load swagger-ui, I don't understand what you mean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OH: We don't net to set it for the container if it's false anyway. Like we have done with enable_swagger.

}

$container->setParameter('api_platform.enable_swagger', $config['enable_swagger']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function getConfigTreeBuilder()
->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end()
->booleanNode('enable_nelmio_api_doc')->defaultValue(false)->info('Enable the Nelmio Api doc integration.')->end()
->booleanNode('enable_swagger')->defaultValue(true)->info('Enable the Swagger documentation and export.')->end()
->booleanNode('enable_swagger_ui')->defaultValue(true)->info('Enable Swagger ui.')->end()

->arrayNode('collection')
->addDefaultsIfNotSet()
Expand Down
15 changes: 15 additions & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/swagger-ui.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" ?>

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

<services>

<service id="api_platform.swagger.listener.ui" class="ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener\SwaggerUiListener">
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
</service>

</services>

</container>
8 changes: 1 addition & 7 deletions src/Bridge/Symfony/Bundle/Resources/config/swagger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@
<argument>%api_platform.title%</argument>
<argument>%api_platform.description%</argument>
</service>

<!-- Event listener -->

<service id="api_platform.swagger.listener.ui" class="ApiPlatform\Core\Bridge\Symfony\Bundle\EventListener\SwaggerUiListener">
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" />
</service>


</services>

</container>
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public function testPrependWhenNotEnabled()
public function testLoadDefaultConfig()
{
$containerBuilderProphecy = $this->getContainerBuilderProphecy();
$containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$this->extension->load(self::DEFAULT_CONFIG, $containerBuilder);
Expand All @@ -133,7 +132,6 @@ public function testSetNameConverter()

$containerBuilderProphecy = $this->getContainerBuilderProphecy();
$containerBuilderProphecy->setAlias('api_platform.name_converter', $nameConverterId)->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['name_converter' => $nameConverterId]]), $containerBuilder);
Expand All @@ -147,7 +145,6 @@ public function testEnableFosUser()
'FOSUserBundle' => FOSUserBundle::class,
])->shouldBeCalled();
$containerBuilderProphecy->setDefinition('api_platform.fos_user.event_listener', Argument::type(Definition::class))->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['enable_fos_user' => true]]), $containerBuilder);
Expand All @@ -162,7 +159,6 @@ public function testEnableNelmioApiDoc()
])->shouldBeCalled();
$containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.annotations_provider', Argument::type(Definition::class))->shouldBeCalled();
$containerBuilderProphecy->setDefinition('api_platform.nelmio_api_doc.parser', Argument::type(Definition::class))->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['enable_nelmio_api_doc' => true]]), $containerBuilder);
Expand All @@ -172,7 +168,6 @@ public function testDisableEagerLoadingExtension()
{
$containerBuilderProphecy = $this->getContainerBuilderProphecy();
$containerBuilderProphecy->setParameter('api_platform.eager_loading.enabled', false)->shouldBeCalled();
$containerBuilderProphecy->setParameter('api_platform.enable_swagger', '1')->shouldBeCalled();
$containerBuilderProphecy->removeDefinition('api_platform.doctrine.orm.query_extension.eager_loading')->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();
$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['eager_loading' => ['enabled' => false]]]), $containerBuilder);
Expand Down Expand Up @@ -202,6 +197,8 @@ private function getContainerBuilderProphecy()
'api_platform.collection.pagination.page_parameter_name' => 'page',
'api_platform.description' => 'description',
'api_platform.error_formats' => ['jsonproblem' => ['application/problem+json'], 'jsonld' => ['application/ld+json']],
'api_platform.enable_swagger' => true,
'api_platform.enable_swagger_ui' => true,
'api_platform.formats' => ['jsonld' => ['application/ld+json'], 'jsonhal' => ['application/hal+json']],
'api_platform.exception_to_status' => [ExceptionInterface::class => Response::HTTP_BAD_REQUEST, InvalidArgumentException::class => Response::HTTP_BAD_REQUEST],
'api_platform.title' => 'title',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testDefaultConfig()
'enable_fos_user' => false,
'enable_nelmio_api_doc' => false,
'enable_swagger' => true,
'enable_swagger_ui' => true,
'eager_loading' => [
'enabled' => true,
'max_joins' => 30,
Expand Down