21
21
use ApiPlatform \OpenApi \Factory \OpenApiFactoryInterface ;
22
22
use ApiPlatform \OpenApi \OpenApi ;
23
23
use ApiPlatform \OpenApi \Serializer \ApiGatewayNormalizer ;
24
+ use ApiPlatform \OpenApi \Serializer \LegacyOpenApiNormalizer ;
24
25
use ApiPlatform \OpenApi \Serializer \OpenApiNormalizer ;
25
26
use ApiPlatform \State \ProcessorInterface ;
26
27
use ApiPlatform \State \ProviderInterface ;
@@ -60,7 +61,11 @@ public function __invoke(Request $request = null)
60
61
return new Documentation ($ this ->resourceNameCollectionFactory ->create (), $ this ->title , $ this ->description , $ this ->version );
61
62
}
62
63
63
- $ context = ['api_gateway ' => $ request ->query ->getBoolean (ApiGatewayNormalizer::API_GATEWAY ), 'base_url ' => $ request ->getBaseUrl ()];
64
+ $ context = [
65
+ 'api_gateway ' => $ request ->query ->getBoolean (ApiGatewayNormalizer::API_GATEWAY ),
66
+ 'base_url ' => $ request ->getBaseUrl (),
67
+ 'spec_version ' => (string ) $ request ->query ->get (LegacyOpenApiNormalizer::SPEC_VERSION ),
68
+ ];
64
69
$ request ->attributes ->set ('_api_normalization_context ' , $ request ->attributes ->get ('_api_normalization_context ' , []) + $ context );
65
70
$ format = $ this ->getRequestFormat ($ request , $ this ->documentationFormats );
66
71
@@ -78,7 +83,18 @@ private function getOpenApiDocumentation(array $context, string $format, Request
78
83
{
79
84
if ($ this ->provider && $ this ->processor ) {
80
85
$ context ['request ' ] = $ request ;
81
- $ operation = new Get (class: OpenApi::class, read: true , serialize: true , provider: fn () => $ this ->openApiFactory ->__invoke ($ context ), normalizationContext: [ApiGatewayNormalizer::API_GATEWAY => $ context ['api_gateway ' ] ?? null ], outputFormats: $ this ->documentationFormats );
86
+ $ operation = new Get (
87
+ class: OpenApi::class,
88
+ read: true ,
89
+ serialize: true ,
90
+ provider: fn () => $ this ->openApiFactory ->__invoke ($ context ),
91
+ normalizationContext: [
92
+ ApiGatewayNormalizer::API_GATEWAY => $ context ['api_gateway ' ] ?? null ,
93
+ LegacyOpenApiNormalizer::SPEC_VERSION => $ context ['spec_version ' ] ?? null ,
94
+ ],
95
+ outputFormats: $ this ->documentationFormats
96
+ );
97
+
82
98
if ('html ' === $ format ) {
83
99
$ operation = $ operation ->withProcessor ('api_platform.swagger_ui.processor ' )->withWrite (true );
84
100
}
0 commit comments