1414namespace ApiPlatform \Symfony \Bundle \SwaggerUi ;
1515
1616use ApiPlatform \Documentation \Documentation ;
17+ use ApiPlatform \Documentation \Entrypoint ;
1718use ApiPlatform \Metadata \Error ;
1819use ApiPlatform \Metadata \Get ;
1920use ApiPlatform \Metadata \HttpOperation ;
@@ -44,6 +45,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4445 !($ operation instanceof HttpOperation)
4546 || !($ request = $ context ['request ' ] ?? null )
4647 || 'html ' !== $ request ->getRequestFormat ()
48+ || true === ($ operation ->getExtraProperties ()['_api_disable_swagger_provider ' ] ?? false )
4749 ) {
4850 return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
4951 }
@@ -55,11 +57,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5557 // We need to call our operation provider just in case it fails
5658 // when it fails we'll get an Error and we'll fix the status accordingly
5759 // @see features/main/content_negotiation.feature:119
58- // DocumentationAction has no content negotation as well we want HTML so render swagger ui
59- if (!$ operation instanceof Error && Documentation::class !== $ operation ->getClass ()) {
60+ // When requesting DocumentationAction or EntrypointAction with Accept: text/html we render SwaggerUi
61+ if (!$ operation instanceof Error && ! \in_array ( $ operation ->getClass (), [Documentation::class, Entrypoint::class], true )) {
6062 $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
6163 }
6264
65+ // This should render only when an error occured
6366 $ swaggerUiOperation = new Get (
6467 class: OpenApi::class,
6568 processor: 'api_platform.swagger_ui.processor ' ,
@@ -71,7 +74,6 @@ class: OpenApi::class,
7174
7275 // save our operation
7376 $ request ->attributes ->set ('_api_operation ' , $ swaggerUiOperation );
74-
7577 $ data = $ this ->openApiFactory ->__invoke (['base_url ' => $ request ->getBaseUrl () ?: '/ ' ]);
7678 $ request ->attributes ->set ('data ' , $ data );
7779
0 commit comments