@@ -24,17 +24,18 @@ class DocumentationActionAppKernel extends \AppKernel
2424{
2525 public static bool $ swaggerUiEnabled = true ;
2626 public static bool $ reDocEnabled = true ;
27+ public static bool $ docsEnabled = true ;
2728
2829 public function getCacheDir (): string
2930 {
30- $ suffix = (self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).(self ::$ reDocEnabled ? 'redoc ' : 'no_redoc ' );
31+ $ suffix = (self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).(self ::$ reDocEnabled ? 'redoc ' : 'no_redoc ' ).( self :: $ docsEnabled ? '' : ' _no_docs ' ) ;
3132
3233 return parent ::getCacheDir ().'/ ' .$ suffix ;
3334 }
3435
3536 public function getLogDir (): string
3637 {
37- $ suffix = (self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).(self ::$ reDocEnabled ? 'redoc ' : 'no_redoc ' );
38+ $ suffix = (self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).(self ::$ reDocEnabled ? 'redoc ' : 'no_redoc ' ).( self :: $ docsEnabled ? '' : ' _no_docs ' ) ;
3839
3940 return parent ::getLogDir ().'/ ' .$ suffix ;
4041 }
@@ -47,6 +48,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
4748 $ container ->loadFromExtension ('api_platform ' , [
4849 'enable_swagger_ui ' => DocumentationActionAppKernel::$ swaggerUiEnabled ,
4950 'enable_re_doc ' => DocumentationActionAppKernel::$ reDocEnabled ,
51+ 'enable_docs ' => DocumentationActionAppKernel::$ docsEnabled ,
5052 ]);
5153 });
5254 }
@@ -158,4 +160,22 @@ public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsEnabled(): void
158160 $ this ->assertJsonContains (['openapi ' => '3.1.0 ' ]);
159161 $ this ->assertJsonContains (['info ' => ['title ' => 'My Dummy API ' ]]);
160162 }
163+
164+ public function testEnableDocsFalseDisablesSwaggerUiAndReDoc (): void
165+ {
166+ DocumentationActionAppKernel::$ swaggerUiEnabled = true ;
167+ DocumentationActionAppKernel::$ reDocEnabled = true ;
168+ DocumentationActionAppKernel::$ docsEnabled = false ;
169+
170+ $ client = self ::createClient ();
171+
172+ $ container = static ::getContainer ();
173+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_docs ' ));
174+ // enable_docs: false acts as a master switch, forcing these to false
175+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
176+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_re_doc ' ));
177+
178+ $ client ->request ('GET ' , '/docs ' , ['headers ' => ['Accept ' => 'text/html ' ]]);
179+ $ this ->assertResponseStatusCodeSame (404 );
180+ }
161181}
0 commit comments