@@ -105,9 +105,19 @@ public function load(array $configs, ContainerBuilder $container): void
105
105
$ configuration = new Configuration ();
106
106
$ config = $ this ->processConfiguration ($ configuration , $ configs );
107
107
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
+
108
117
$ formats = $ this ->getFormats ($ config ['formats ' ]);
109
118
$ patchFormats = $ this ->getFormats ($ config ['patch_formats ' ]);
110
119
$ errorFormats = $ this ->getFormats ($ config ['error_formats ' ]);
120
+ $ docsFormats = $ this ->getFormats ($ config ['docs_formats ' ]);
111
121
112
122
if (!isset ($ errorFormats ['html ' ]) && $ config ['enable_swagger ' ] && $ config ['enable_swagger_ui ' ]) {
113
123
$ errorFormats ['html ' ] = ['text/html ' ];
@@ -122,7 +132,12 @@ public function load(array $configs, ContainerBuilder $container): void
122
132
$ patchFormats ['jsonapi ' ] = ['application/vnd.api+json ' ];
123
133
}
124
134
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 );
126
141
$ this ->registerMetadataConfiguration ($ container , $ config , $ loader );
127
142
$ this ->registerOAuthConfiguration ($ container , $ config );
128
143
$ this ->registerOpenApiConfiguration ($ container , $ config , $ loader );
@@ -159,7 +174,7 @@ public function load(array $configs, ContainerBuilder $container): void
159
174
$ this ->registerInflectorConfiguration ($ config );
160
175
}
161
176
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
163
178
{
164
179
$ loader ->load ('symfony/events.xml ' );
165
180
$ loader ->load ('symfony/controller.xml ' );
@@ -191,6 +206,7 @@ private function registerCommonConfiguration(ContainerBuilder $container, array
191
206
$ container ->setParameter ('api_platform.formats ' , $ formats );
192
207
$ container ->setParameter ('api_platform.patch_formats ' , $ patchFormats );
193
208
$ container ->setParameter ('api_platform.error_formats ' , $ errorFormats );
209
+ $ container ->setParameter ('api_platform.docs_formats ' , $ docsFormats );
194
210
$ container ->setParameter ('api_platform.eager_loading.enabled ' , $ this ->isConfigEnabled ($ container , $ config ['eager_loading ' ]));
195
211
$ container ->setParameter ('api_platform.eager_loading.max_joins ' , $ config ['eager_loading ' ]['max_joins ' ]);
196
212
$ container ->setParameter ('api_platform.eager_loading.fetch_partial ' , $ config ['eager_loading ' ]['fetch_partial ' ]);
@@ -286,7 +302,8 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
286
302
287
303
if (!empty ($ config ['resource_class_directories ' ])) {
288
304
$ 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 ' )
290
307
));
291
308
}
292
309
0 commit comments