2323class DocumentationActionAppKernel extends \AppKernel
2424{
2525 public static bool $ swaggerUiEnabled = true ;
26+ public static bool $ reDocEnabled = true ;
2627
2728 public function getCacheDir (): string
2829 {
29- $ suffix = self ::$ swaggerUiEnabled ? 'ui_enabled ' : 'ui_disabled ' ;
30+ $ suffix = ( self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).( self :: $ reDocEnabled ? ' redoc ' : ' no_redoc ' ) ;
3031
3132 return parent ::getCacheDir ().'/ ' .$ suffix ;
3233 }
3334
3435 public function getLogDir (): string
3536 {
36- $ suffix = self ::$ swaggerUiEnabled ? 'ui_enabled ' : 'ui_disabled ' ;
37+ $ suffix = ( self ::$ swaggerUiEnabled ? 'ui_ ' : 'no_ui_ ' ).( self :: $ reDocEnabled ? ' redoc ' : ' no_redoc ' ) ;
3738
3839 return parent ::getLogDir ().'/ ' .$ suffix ;
3940 }
@@ -45,6 +46,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
4546 $ loader ->load (static function (ContainerBuilder $ container ) {
4647 $ container ->loadFromExtension ('api_platform ' , [
4748 'enable_swagger_ui ' => DocumentationActionAppKernel::$ swaggerUiEnabled ,
49+ 'enable_re_doc ' => DocumentationActionAppKernel::$ reDocEnabled ,
4850 ]);
4951 });
5052 }
@@ -59,57 +61,97 @@ protected static function getKernelClass(): string
5961 return DocumentationActionAppKernel::class;
6062 }
6163
62- public function testHtmlDocumentationIsNotAccessibleWhenSwaggerUiIsDisabled (): void
64+ public function testHtmlDocumentationIsNotAccessibleWhenSwaggerUiAndReDocAreDisabled (): void
6365 {
6466 DocumentationActionAppKernel::$ swaggerUiEnabled = false ;
67+ DocumentationActionAppKernel::$ reDocEnabled = false ;
6568
6669 $ client = self ::createClient ();
6770
6871 $ container = static ::getContainer ();
6972 $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
73+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_re_doc ' ));
7074
7175 $ client ->request ('GET ' , '/docs ' , ['headers ' => ['Accept ' => 'text/html ' ]]);
7276 $ this ->assertResponseStatusCodeSame (404 );
73- $ this ->assertStringContainsString ('Swagger UI is disabled. ' , $ client ->getResponse ()->getContent (false ));
77+ $ this ->assertStringContainsString ('Swagger UI and ReDoc are disabled. ' , $ client ->getResponse ()->getContent (false ));
7478 }
7579
7680 public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsDisabled (): void
7781 {
7882 DocumentationActionAppKernel::$ swaggerUiEnabled = false ;
83+ DocumentationActionAppKernel::$ reDocEnabled = false ;
7984
8085 $ client = self ::createClient ();
8186
8287 $ container = static ::getContainer ();
8388 $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
89+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_re_doc ' ));
8490
8591 $ client ->request ('GET ' , '/docs.jsonopenapi ' , ['headers ' => ['Accept ' => 'application/vnd.openapi+json ' ]]);
8692 $ this ->assertResponseIsSuccessful ();
8793 $ this ->assertJsonContains (['openapi ' => '3.1.0 ' ]);
8894 $ this ->assertJsonContains (['info ' => ['title ' => 'My Dummy API ' ]]);
8995 }
9096
97+ public function testHtmlDocumentationIsAccessibleWhenReDocEnabledAndSwaggerUiDisabled (): void
98+ {
99+ DocumentationActionAppKernel::$ swaggerUiEnabled = false ;
100+ DocumentationActionAppKernel::$ reDocEnabled = true ;
101+
102+ $ client = self ::createClient ();
103+
104+ $ container = static ::getContainer ();
105+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
106+ $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_re_doc ' ));
107+
108+ $ client ->request ('GET ' , '/docs ' , ['headers ' => ['Accept ' => 'text/html ' ]]);
109+ $ this ->assertResponseIsSuccessful ();
110+ $ this ->assertStringNotContainsString ('Swagger UI and ReDoc are disabled. ' , $ client ->getResponse ()->getContent (false ));
111+ }
112+
113+ public function testHtmlDocumentationIsAccessibleWhenSwaggerUiEnabledAndReDocDisabled (): void
114+ {
115+ DocumentationActionAppKernel::$ swaggerUiEnabled = true ;
116+ DocumentationActionAppKernel::$ reDocEnabled = false ;
117+
118+ $ client = self ::createClient ();
119+
120+ $ container = static ::getContainer ();
121+ $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
122+ $ this ->assertFalse ($ container ->getParameter ('api_platform.enable_re_doc ' ));
123+
124+ $ client ->request ('GET ' , '/docs ' , ['headers ' => ['Accept ' => 'text/html ' ]]);
125+ $ this ->assertResponseIsSuccessful ();
126+ $ this ->assertStringNotContainsString ('Swagger UI and ReDoc are disabled. ' , $ client ->getResponse ()->getContent (false ));
127+ }
128+
91129 public function testHtmlDocumentationIsAccessibleWhenSwaggerUiIsEnabled (): void
92130 {
93131 DocumentationActionAppKernel::$ swaggerUiEnabled = true ;
132+ DocumentationActionAppKernel::$ reDocEnabled = true ;
94133
95134 $ client = self ::createClient ();
96135
97136 $ container = static ::getContainer ();
98137 $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
138+ $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_re_doc ' ));
99139
100140 $ client ->request ('GET ' , '/docs ' , ['headers ' => ['Accept ' => 'text/html ' ]]);
101141 $ this ->assertResponseIsSuccessful ();
102- $ this ->assertStringNotContainsString ('Swagger UI is disabled. ' , $ client ->getResponse ()->getContent (false ));
142+ $ this ->assertStringNotContainsString ('Swagger UI and ReDoc are disabled. ' , $ client ->getResponse ()->getContent (false ));
103143 }
104144
105145 public function testJsonDocumentationIsAccessibleWhenSwaggerUiIsEnabled (): void
106146 {
107147 DocumentationActionAppKernel::$ swaggerUiEnabled = true ;
148+ DocumentationActionAppKernel::$ reDocEnabled = true ;
108149
109150 $ client = self ::createClient ();
110151
111152 $ container = static ::getContainer ();
112153 $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_swagger_ui ' ));
154+ $ this ->assertTrue ($ container ->getParameter ('api_platform.enable_re_doc ' ));
113155
114156 $ client ->request ('GET ' , '/docs.jsonopenapi ' , ['headers ' => ['Accept ' => 'application/vnd.openapi+json ' ]]);
115157 $ this ->assertResponseIsSuccessful ();
0 commit comments