@@ -105,9 +105,19 @@ public function load(array $configs, ContainerBuilder $container): void
105105 $ configuration = new Configuration ();
106106 $ config = $ this ->processConfiguration ($ configuration , $ configs );
107107
108+ if (!$ config ['formats ' ]) {
109+ trigger_deprecation ('api-platform/core ' , '3.2 ' , 'Setting the "formats" section will be mandatory in API Platform 4. ' );
110+ $ config ['formats ' ] = [
111+ 'jsonld ' => ['mime_types ' => ['application/ld+json ' ]],
112+ // Note that in API Platform 4 this will be removed as it was used for documentation only and are is now present in the docsFormats
113+ 'json ' => ['mime_types ' => ['application/json ' ]], // Swagger support
114+ ];
115+ }
116+
108117 $ formats = $ this ->getFormats ($ config ['formats ' ]);
109118 $ patchFormats = $ this ->getFormats ($ config ['patch_formats ' ]);
110119 $ errorFormats = $ this ->getFormats ($ config ['error_formats ' ]);
120+ $ docsFormats = $ this ->getFormats ($ config ['docs_formats ' ]);
111121
112122 if (!isset ($ errorFormats ['html ' ]) && $ config ['enable_swagger ' ] && $ config ['enable_swagger_ui ' ]) {
113123 $ errorFormats ['html ' ] = ['text/html ' ];
@@ -122,7 +132,12 @@ public function load(array $configs, ContainerBuilder $container): void
122132 $ patchFormats ['jsonapi ' ] = ['application/vnd.api+json ' ];
123133 }
124134
125- $ this ->registerCommonConfiguration ($ container , $ config , $ loader , $ formats , $ patchFormats , $ errorFormats );
135+ if (isset ($ docsFormats ['json ' ]) && !isset ($ docsFormats ['jsonopenapi ' ])) {
136+ trigger_deprecation ('api-platform/core ' , '3.2 ' , 'The "json" format is too broad, use ["jsonopenapi" => ["application/vnd.openapi+json"]] instead. ' );
137+ $ docsFormats ['jsonopenapi ' ] = ['application/vnd.openapi+json ' ];
138+ }
139+
140+ $ this ->registerCommonConfiguration ($ container , $ config , $ loader , $ formats , $ patchFormats , $ errorFormats , $ docsFormats );
126141 $ this ->registerMetadataConfiguration ($ container , $ config , $ loader );
127142 $ this ->registerOAuthConfiguration ($ container , $ config );
128143 $ this ->registerOpenApiConfiguration ($ container , $ config , $ loader );
@@ -159,7 +174,7 @@ public function load(array $configs, ContainerBuilder $container): void
159174 $ this ->registerInflectorConfiguration ($ config );
160175 }
161176
162- private function registerCommonConfiguration (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader , array $ formats , array $ patchFormats , array $ errorFormats ): void
177+ private function registerCommonConfiguration (ContainerBuilder $ container , array $ config , XmlFileLoader $ loader , array $ formats , array $ patchFormats , array $ errorFormats, array $ docsFormats ): void
163178 {
164179 $ loader ->load ('symfony/events.xml ' );
165180 $ loader ->load ('symfony/controller.xml ' );
@@ -191,6 +206,7 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
191206 $ container ->setParameter ('api_platform.formats ' , $ formats );
192207 $ container ->setParameter ('api_platform.patch_formats ' , $ patchFormats );
193208 $ container ->setParameter ('api_platform.error_formats ' , $ errorFormats );
209+ $ container ->setParameter ('api_platform.docs_formats ' , $ docsFormats );
194210 $ container ->setParameter ('api_platform.eager_loading.enabled ' , $ this ->isConfigEnabled ($ container , $ config ['eager_loading ' ]));
195211 $ container ->setParameter ('api_platform.eager_loading.max_joins ' , $ config ['eager_loading ' ]['max_joins ' ]);
196212 $ container ->setParameter ('api_platform.eager_loading.fetch_partial ' , $ config ['eager_loading ' ]['fetch_partial ' ]);
@@ -286,7 +302,8 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
286302
287303 if (!empty ($ config ['resource_class_directories ' ])) {
288304 $ container ->setParameter ('api_platform.resource_class_directories ' , array_merge (
289- $ config ['resource_class_directories ' ], $ container ->getParameter ('api_platform.resource_class_directories ' )
305+ $ config ['resource_class_directories ' ],
306+ $ container ->getParameter ('api_platform.resource_class_directories ' )
290307 ));
291308 }
292309
0 commit comments