From d4e182ec8bb2618506e6171b5241e7c6f60e43b2 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Thu, 20 Nov 2025 16:10:43 +0100 Subject: [PATCH 1/7] fix(symfony): disable Swagger UI and keep openapi.json --- src/Symfony/Action/DocumentationAction.php | 8 +++++++- .../DependencyInjection/ApiPlatformExtension.php | 10 +++++----- .../Bundle/Resources/config/symfony/controller.php | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Symfony/Action/DocumentationAction.php b/src/Symfony/Action/DocumentationAction.php index 0e294671b33..d2e1048eb34 100644 --- a/src/Symfony/Action/DocumentationAction.php +++ b/src/Symfony/Action/DocumentationAction.php @@ -28,6 +28,7 @@ use Negotiation\Negotiator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Generates the API documentation. @@ -48,6 +49,7 @@ public function __construct( private readonly ?ProcessorInterface $processor = null, ?Negotiator $negotiator = null, private readonly array $documentationFormats = [OpenApiNormalizer::JSON_FORMAT => ['application/vnd.openapi+json'], OpenApiNormalizer::FORMAT => ['application/json']], + private readonly bool $swaggerUiEnabled = true, ) { $this->negotiator = $negotiator ?? new Negotiator(); } @@ -83,6 +85,10 @@ public function __invoke(?Request $request = null) */ private function getOpenApiDocumentation(array $context, string $format, Request $request): OpenApi|Response { + if ('html' === $format && !$this->swaggerUiEnabled) { + throw new NotFoundHttpException('Swagger UI is disabled.'); + } + if ($this->provider && $this->processor) { $context['request'] = $request; $operation = new Get( @@ -93,7 +99,7 @@ class: OpenApi::class, outputFormats: $this->documentationFormats ); - if ('html' === $format) { + if ('html' === $format && $this->swaggerUiEnabled) { $operation = $operation->withProcessor('api_platform.swagger_ui.processor')->withWrite(true); } diff --git a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php index 805b6d1e2cb..c4c5bae2ec4 100644 --- a/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php +++ b/src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php @@ -586,13 +586,13 @@ private function registerSwaggerConfiguration(ContainerBuilder $container, array $loader->load('openapi/yaml.php'); } - $loader->load('swagger_ui.php'); + if ($config['enable_swagger_ui']) { + $loader->load('swagger_ui.php'); - if ($config['use_symfony_listeners']) { - $loader->load('symfony/swagger_ui.php'); - } + if ($config['use_symfony_listeners']) { + $loader->load('symfony/swagger_ui.php'); + } - if ($config['enable_swagger_ui']) { $loader->load('state/swagger_ui.php'); } diff --git a/src/Symfony/Bundle/Resources/config/symfony/controller.php b/src/Symfony/Bundle/Resources/config/symfony/controller.php index f0cb19075a2..046bd59c2c8 100644 --- a/src/Symfony/Bundle/Resources/config/symfony/controller.php +++ b/src/Symfony/Bundle/Resources/config/symfony/controller.php @@ -47,5 +47,6 @@ service('api_platform.state_processor.main'), service('api_platform.negotiator')->nullOnInvalid(), '%api_platform.docs_formats%', + '%api_platform.enable_swagger_ui%', ]); }; From 31e18245a7cb0b75b973f3dd6d05300009fa82d7 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Thu, 20 Nov 2025 17:18:35 +0100 Subject: [PATCH 2/7] test: add tests in ApiPlatformExtensionTest --- .../ApiPlatformExtensionTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 9b7b0972ad5..aa1b775d775 100644 --- a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -208,6 +208,10 @@ public function testCommonConfiguration(): void 'api_platform.state_processor.respond', 'api_platform.state_processor.add_link_header', 'api_platform.state_processor.serialize', + + 'api_platform.swagger_ui.context', + 'api_platform.swagger_ui.processor', + 'api_platform.swagger_ui.provider', ]; $aliases = [ @@ -256,6 +260,43 @@ public function testCommonConfiguration(): void } } + public function testSwaggerUiDisabledConfiguration(): void + { + $config = self::DEFAULT_CONFIG; + $config['api_platform']['enable_swagger'] = true; + $config['api_platform']['enable_swagger_ui'] = false; + $config['api_platform']['use_symfony_listeners'] = true; + + (new ApiPlatformExtension())->load($config, $this->container); + + $this->assertNotContainerHasService('api_platform.swagger_ui.processor'); + + $this->assertNotContainerHasService('api_platform.swagger_ui.context'); + + $this->assertNotContainerHasService('api_platform.swagger_ui.provider'); + + $this->assertNotContainerHasService('api_platform.swagger_ui.documentation.provider'); + } + + public function testSwaggerUiEnabledConfiguration(): void + { + $config = self::DEFAULT_CONFIG; + $config['api_platform']['enable_swagger'] = true; + $config['api_platform']['enable_swagger_ui'] = true; + $config['api_platform']['use_symfony_listeners'] = true; + + (new ApiPlatformExtension())->load($config, $this->container); + + $services = [ + 'api_platform.swagger_ui.processor', + 'api_platform.swagger_ui.context', + 'api_platform.swagger_ui.provider', + 'api_platform.swagger_ui.documentation.provider', + ]; + + $this->assertContainerHas($services); + } + public function testEventListenersConfiguration(): void { $config = self::DEFAULT_CONFIG; From bbfa7641649f15ad5138715bdbec9e6caa0415e4 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Fri, 21 Nov 2025 10:03:40 +0100 Subject: [PATCH 3/7] test: improve ApiPlatformExtensionTest::testCommonConfiguration --- .../Bundle/DependencyInjection/ApiPlatformExtensionTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index aa1b775d775..440f6417c1d 100644 --- a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -253,6 +253,7 @@ public function testCommonConfiguration(): void 'api_platform.listener.view.write', 'api_platform.listener.view.serialize', 'api_platform.listener.view.respond', + 'api_platform.swagger_ui.documentation.provider', ]; foreach ($services as $service) { @@ -264,11 +265,11 @@ public function testSwaggerUiDisabledConfiguration(): void { $config = self::DEFAULT_CONFIG; $config['api_platform']['enable_swagger'] = true; - $config['api_platform']['enable_swagger_ui'] = false; + $config['api_platform']['enable_swagger_ui'] = false; $config['api_platform']['use_symfony_listeners'] = true; (new ApiPlatformExtension())->load($config, $this->container); - + $this->assertNotContainerHasService('api_platform.swagger_ui.processor'); $this->assertNotContainerHasService('api_platform.swagger_ui.context'); From 23dc74b4b6917de01776537fd4b681c1c3680ed2 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Fri, 21 Nov 2025 13:20:51 +0100 Subject: [PATCH 4/7] test: add tests in DocumentationActionTest --- .../Tests/Action/DocumentationActionTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/Symfony/Tests/Action/DocumentationActionTest.php b/src/Symfony/Tests/Action/DocumentationActionTest.php index 7fbec7e5288..6e2ca6fe028 100644 --- a/src/Symfony/Tests/Action/DocumentationActionTest.php +++ b/src/Symfony/Tests/Action/DocumentationActionTest.php @@ -27,6 +27,7 @@ use Prophecy\Argument; use Prophecy\PhpUnit\ProphecyTrait; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * @author Amrouche Hamza @@ -35,6 +36,50 @@ class DocumentationActionTest extends TestCase { use ProphecyTrait; + public function testHtmlFormatWhenSwaggerUiDisabledThrows404(): void + { + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('Swagger UI is disabled.'); + + $request = new Request(); + $request->attributes->set('_format', 'html'); + + $openApiFactory = $this->createMock(OpenApiFactoryInterface::class); + $resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class); + + $documentation = new DocumentationAction( + $resourceNameCollectionFactory, + openApiFactory: $openApiFactory, + documentationFormats: [ + 'json' => ['application/json'], + 'html' => ['text/html'], + ], + swaggerUiEnabled: false, + ); + + $documentation($request); + } + + public function testJsonFormatWhenSwaggerUiDisabledIsAccessible(): void + { + $request = new Request(); + $request->attributes->set('_format', 'json'); + + $openApiFactory = $this->createMock(OpenApiFactoryInterface::class); + $openApiFactory->expects($this->once())->method('__invoke')->willReturn(new OpenApi(new Info('title', '1.0.0'), [], new Paths())); + + $resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class); + + $documentation = new DocumentationAction( + $resourceNameCollectionFactory, + openApiFactory: $openApiFactory, + swaggerUiEnabled: false + ); + + $result = $documentation($request); + $this->assertInstanceOf(OpenApi::class, $result); + } + public function testDocumentationAction(): void { $openApi = new OpenApi(new Info('my api', '1.0.0'), [], new Paths()); From 0836b83956e777f7d4fcee50cf8b423c28269a1a Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Fri, 21 Nov 2025 13:24:24 +0100 Subject: [PATCH 5/7] test: improve DocumentationActionTest by adding test for not supported html format verification --- .../Tests/Action/DocumentationActionTest.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Symfony/Tests/Action/DocumentationActionTest.php b/src/Symfony/Tests/Action/DocumentationActionTest.php index 6e2ca6fe028..4328c933329 100644 --- a/src/Symfony/Tests/Action/DocumentationActionTest.php +++ b/src/Symfony/Tests/Action/DocumentationActionTest.php @@ -133,4 +133,25 @@ public function testGetHydraDocumentation(): void $entrypoint = new DocumentationAction($resourceNameCollectionFactory, provider: $provider, processor: $processor); $entrypoint($request); } + + public function testHtmlFormatNotSupportedThrowsException(): void + { + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('Format "html" is not supported'); + + $request = new Request(); + $request->attributes->set('_format', 'html'); + + $openApiFactory = $this->createMock(OpenApiFactoryInterface::class); + $resourceNameCollectionFactory = $this->createMock(ResourceNameCollectionFactoryInterface::class); + + $documentation = new DocumentationAction( + $resourceNameCollectionFactory, + openApiFactory: $openApiFactory, + documentationFormats: ['json' => ['application/json']], + swaggerUiEnabled: false, + ); + + $documentation($request); + } } From 9201e5707833f1c4ff4d3baf3067b771909f12f9 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Sun, 23 Nov 2025 23:22:27 +0100 Subject: [PATCH 6/7] test: add tests in tests/Functional/DocumentationActionTest.php --- .../app/config/config_swagger_ui_disabled.yml | 6 ++ .../app/config/config_swagger_ui_enabled.yml | 6 ++ .../config/routing_swagger_ui_disabled.yml | 2 + .../app/config/routing_swagger_ui_enabled.yml | 2 + tests/Functional/DocumentationActionTest.php | 65 +++++++++++++++++++ 5 files changed, 81 insertions(+) create mode 100644 tests/Fixtures/app/config/config_swagger_ui_disabled.yml create mode 100644 tests/Fixtures/app/config/config_swagger_ui_enabled.yml create mode 100644 tests/Fixtures/app/config/routing_swagger_ui_disabled.yml create mode 100644 tests/Fixtures/app/config/routing_swagger_ui_enabled.yml create mode 100644 tests/Functional/DocumentationActionTest.php diff --git a/tests/Fixtures/app/config/config_swagger_ui_disabled.yml b/tests/Fixtures/app/config/config_swagger_ui_disabled.yml new file mode 100644 index 00000000000..3d1b9a738c7 --- /dev/null +++ b/tests/Fixtures/app/config/config_swagger_ui_disabled.yml @@ -0,0 +1,6 @@ +imports: + - { resource: config_test.yml } + +api_platform: + enable_swagger: true + enable_swagger_ui: false \ No newline at end of file diff --git a/tests/Fixtures/app/config/config_swagger_ui_enabled.yml b/tests/Fixtures/app/config/config_swagger_ui_enabled.yml new file mode 100644 index 00000000000..fb53ab34abc --- /dev/null +++ b/tests/Fixtures/app/config/config_swagger_ui_enabled.yml @@ -0,0 +1,6 @@ +imports: + - { resource: config_test.yml } + +api_platform: + enable_swagger: true + enable_swagger_ui: true diff --git a/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml b/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml new file mode 100644 index 00000000000..61bf428fc8f --- /dev/null +++ b/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml @@ -0,0 +1,2 @@ +_main: + resource: routing_test.yml \ No newline at end of file diff --git a/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml b/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml new file mode 100644 index 00000000000..61bf428fc8f --- /dev/null +++ b/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml @@ -0,0 +1,2 @@ +_main: + resource: routing_test.yml \ No newline at end of file diff --git a/tests/Functional/DocumentationActionTest.php b/tests/Functional/DocumentationActionTest.php new file mode 100644 index 00000000000..021357c7be8 --- /dev/null +++ b/tests/Functional/DocumentationActionTest.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace ApiPlatform\Tests\Functional; + +use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; +use ApiPlatform\Symfony\Bundle\Test\Client; + +class DocumentationActionTest extends ApiTestCase +{ + protected static ?bool $alwaysBootKernel = true; + + private function createClientWithEnv(string $env): Client + { + return self::createClient(['environment' => $env]); + } + + public function testHtmlDocumentationIsNotAccessibleWhenSwaggerUiIsDisabled(): void + { + $client = $this->createClientWithEnv('swagger_ui_disabled'); + + $client->request('GET', '/docs', ['headers' => ['Accept' => 'text/html']]); + $this->assertResponseStatusCodeSame(404); + $this->assertStringContainsString('Swagger UI is disabled.', $client->getResponse()->getContent(false)); + } + + public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsDisabled(): void + { + $client = $this->createClientWithEnv('swagger_ui_disabled'); + + $client->request('GET', '/docs.jsonopenapi', ['headers' => ['Accept' => 'application/vnd.openapi+json']]); + $this->assertResponseIsSuccessful(); + $this->assertJsonContains(['openapi' => '3.1.0']); + $this->assertJsonContains(['info' => ['title' => 'My Dummy API']]); + } + + public function testHtmlDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void + { + $client = $this->createClientWithEnv('swagger_ui_enabled'); + + $client->request('GET', '/docs', ['headers' => ['Accept' => 'text/html']]); + $this->assertResponseIsSuccessful(); + $this->assertStringNotContainsString('Swagger UI is disabled.', $client->getResponse()->getContent(false)); + } + + public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void + { + $client = $this->createClientWithEnv('swagger_ui_enabled'); + + $client->request('GET', '/docs.jsonopenapi', ['headers' => ['Accept' => 'application/vnd.openapi+json']]); + $this->assertResponseIsSuccessful(); + $this->assertJsonContains(['openapi' => '3.1.0']); + $this->assertJsonContains(['info' => ['title' => 'My Dummy API']]); + } +} From 620ddc3c5a7251639bccd3f7a049d9fb0c80f254 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Mon, 24 Nov 2025 12:32:13 +0100 Subject: [PATCH 7/7] fix(ci): fix tests in tests/Functional/DocumentationActionTest.php --- .../Resources/config/symfony/events.php | 1 + .../ApiPlatformExtensionTest.php | 2 + tests/Fixtures/app/config/config_common.yml | 2 + .../app/config/config_swagger_ui_disabled.yml | 6 -- .../app/config/config_swagger_ui_enabled.yml | 6 -- .../config/routing_swagger_ui_disabled.yml | 2 - .../app/config/routing_swagger_ui_enabled.yml | 2 - tests/Functional/DocumentationActionTest.php | 70 ++++++++++++++++--- 8 files changed, 67 insertions(+), 24 deletions(-) delete mode 100644 tests/Fixtures/app/config/config_swagger_ui_disabled.yml delete mode 100644 tests/Fixtures/app/config/config_swagger_ui_enabled.yml delete mode 100644 tests/Fixtures/app/config/routing_swagger_ui_disabled.yml delete mode 100644 tests/Fixtures/app/config/routing_swagger_ui_enabled.yml diff --git a/src/Symfony/Bundle/Resources/config/symfony/events.php b/src/Symfony/Bundle/Resources/config/symfony/events.php index 1f368138281..dcc22eba0cc 100644 --- a/src/Symfony/Bundle/Resources/config/symfony/events.php +++ b/src/Symfony/Bundle/Resources/config/symfony/events.php @@ -179,6 +179,7 @@ service('api_platform.state_processor.documentation'), service('api_platform.negotiator')->nullOnInvalid(), '%api_platform.docs_formats%', + '%api_platform.enable_swagger_ui%', ]); $services->set('api_platform.action.placeholder', 'ApiPlatform\Symfony\Action\PlaceholderAction') diff --git a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php index 440f6417c1d..c8ac31f8445 100644 --- a/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php +++ b/src/Symfony/Tests/Bundle/DependencyInjection/ApiPlatformExtensionTest.php @@ -108,6 +108,8 @@ class ApiPlatformExtensionTest extends TestCase 'asset_package' => null, 'enable_entrypoint' => true, 'enable_docs' => true, + 'enable_swagger' => true, + 'enable_swagger_ui' => true, 'use_symfony_listeners' => false, ]]; diff --git a/tests/Fixtures/app/config/config_common.yml b/tests/Fixtures/app/config/config_common.yml index f9d2cd2afba..482fdb51c6e 100644 --- a/tests/Fixtures/app/config/config_common.yml +++ b/tests/Fixtures/app/config/config_common.yml @@ -36,6 +36,8 @@ api_platform: description: | This is a test API. Made with love + enable_swagger: true + enable_swagger_ui: true formats: jsonld: ['application/ld+json'] jsonhal: ['application/hal+json'] diff --git a/tests/Fixtures/app/config/config_swagger_ui_disabled.yml b/tests/Fixtures/app/config/config_swagger_ui_disabled.yml deleted file mode 100644 index 3d1b9a738c7..00000000000 --- a/tests/Fixtures/app/config/config_swagger_ui_disabled.yml +++ /dev/null @@ -1,6 +0,0 @@ -imports: - - { resource: config_test.yml } - -api_platform: - enable_swagger: true - enable_swagger_ui: false \ No newline at end of file diff --git a/tests/Fixtures/app/config/config_swagger_ui_enabled.yml b/tests/Fixtures/app/config/config_swagger_ui_enabled.yml deleted file mode 100644 index fb53ab34abc..00000000000 --- a/tests/Fixtures/app/config/config_swagger_ui_enabled.yml +++ /dev/null @@ -1,6 +0,0 @@ -imports: - - { resource: config_test.yml } - -api_platform: - enable_swagger: true - enable_swagger_ui: true diff --git a/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml b/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml deleted file mode 100644 index 61bf428fc8f..00000000000 --- a/tests/Fixtures/app/config/routing_swagger_ui_disabled.yml +++ /dev/null @@ -1,2 +0,0 @@ -_main: - resource: routing_test.yml \ No newline at end of file diff --git a/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml b/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml deleted file mode 100644 index 61bf428fc8f..00000000000 --- a/tests/Fixtures/app/config/routing_swagger_ui_enabled.yml +++ /dev/null @@ -1,2 +0,0 @@ -_main: - resource: routing_test.yml \ No newline at end of file diff --git a/tests/Functional/DocumentationActionTest.php b/tests/Functional/DocumentationActionTest.php index 021357c7be8..707759866e0 100644 --- a/tests/Functional/DocumentationActionTest.php +++ b/tests/Functional/DocumentationActionTest.php @@ -14,20 +14,59 @@ namespace ApiPlatform\Tests\Functional; use ApiPlatform\Symfony\Bundle\Test\ApiTestCase; -use ApiPlatform\Symfony\Bundle\Test\Client; +use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; -class DocumentationActionTest extends ApiTestCase +/** + * @author Maxence Castel + */ +class DocumentationActionAppKernel extends \AppKernel +{ + public static bool $swaggerUiEnabled = true; + + public function getCacheDir(): string + { + $suffix = self::$swaggerUiEnabled ? 'ui_enabled' : 'ui_disabled'; + + return parent::getCacheDir().'/'.$suffix; + } + + public function getLogDir(): string + { + $suffix = self::$swaggerUiEnabled ? 'ui_enabled' : 'ui_disabled'; + + return parent::getLogDir().'/'.$suffix; + } + + protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader): void + { + parent::configureContainer($c, $loader); + + $loader->load(static function (ContainerBuilder $container) { + $container->loadFromExtension('api_platform', [ + 'enable_swagger_ui' => DocumentationActionAppKernel::$swaggerUiEnabled, + ]); + }); + } +} + +final class DocumentationActionTest extends ApiTestCase { protected static ?bool $alwaysBootKernel = true; - private function createClientWithEnv(string $env): Client + protected static function getKernelClass(): string { - return self::createClient(['environment' => $env]); + return DocumentationActionAppKernel::class; } public function testHtmlDocumentationIsNotAccessibleWhenSwaggerUiIsDisabled(): void { - $client = $this->createClientWithEnv('swagger_ui_disabled'); + DocumentationActionAppKernel::$swaggerUiEnabled = false; + + $client = self::createClient(); + + $container = static::getContainer(); + $this->assertFalse($container->getParameter('api_platform.enable_swagger_ui')); $client->request('GET', '/docs', ['headers' => ['Accept' => 'text/html']]); $this->assertResponseStatusCodeSame(404); @@ -36,7 +75,12 @@ public function testHtmlDocumentationIsNotAccessibleWhenSwaggerUiIsDisabled(): v public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsDisabled(): void { - $client = $this->createClientWithEnv('swagger_ui_disabled'); + DocumentationActionAppKernel::$swaggerUiEnabled = false; + + $client = self::createClient(); + + $container = static::getContainer(); + $this->assertFalse($container->getParameter('api_platform.enable_swagger_ui')); $client->request('GET', '/docs.jsonopenapi', ['headers' => ['Accept' => 'application/vnd.openapi+json']]); $this->assertResponseIsSuccessful(); @@ -46,7 +90,12 @@ public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsDisabled(): void public function testHtmlDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void { - $client = $this->createClientWithEnv('swagger_ui_enabled'); + DocumentationActionAppKernel::$swaggerUiEnabled = true; + + $client = self::createClient(); + + $container = static::getContainer(); + $this->assertTrue($container->getParameter('api_platform.enable_swagger_ui')); $client->request('GET', '/docs', ['headers' => ['Accept' => 'text/html']]); $this->assertResponseIsSuccessful(); @@ -55,7 +104,12 @@ public function testHtmlDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void { - $client = $this->createClientWithEnv('swagger_ui_enabled'); + DocumentationActionAppKernel::$swaggerUiEnabled = true; + + $client = self::createClient(); + + $container = static::getContainer(); + $this->assertTrue($container->getParameter('api_platform.enable_swagger_ui')); $client->request('GET', '/docs.jsonopenapi', ['headers' => ['Accept' => 'application/vnd.openapi+json']]); $this->assertResponseIsSuccessful();