14
14
namespace ApiPlatform \Symfony \Bundle \SwaggerUi ;
15
15
16
16
use ApiPlatform \Documentation \Documentation ;
17
+ use ApiPlatform \Documentation \Entrypoint ;
17
18
use ApiPlatform \Metadata \Error ;
18
19
use ApiPlatform \Metadata \Get ;
19
20
use ApiPlatform \Metadata \HttpOperation ;
@@ -44,6 +45,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
44
45
!($ operation instanceof HttpOperation)
45
46
|| !($ request = $ context ['request ' ] ?? null )
46
47
|| 'html ' !== $ request ->getRequestFormat ()
48
+ || true === ($ operation ->getExtraProperties ()['_api_disable_swagger_provider ' ] ?? false )
47
49
) {
48
50
return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
49
51
}
@@ -55,11 +57,12 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
55
57
// We need to call our operation provider just in case it fails
56
58
// when it fails we'll get an Error and we'll fix the status accordingly
57
59
// @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 )) {
60
62
$ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
61
63
}
62
64
65
+ // This should render only when an error occured
63
66
$ swaggerUiOperation = new Get (
64
67
class: OpenApi::class,
65
68
processor: 'api_platform.swagger_ui.processor ' ,
@@ -71,7 +74,6 @@ class: OpenApi::class,
71
74
72
75
// save our operation
73
76
$ request ->attributes ->set ('_api_operation ' , $ swaggerUiOperation );
74
-
75
77
$ data = $ this ->openApiFactory ->__invoke (['base_url ' => $ request ->getBaseUrl () ?: '/ ' ]);
76
78
$ request ->attributes ->set ('data ' , $ data );
77
79
0 commit comments