@@ -262,6 +262,91 @@ services:
262
262
Both the `input` and the `output` attributes can be set to `false`. If `input` is `false`, the deserialization process
263
263
will be skipped. If `output` is `false`, the serialization process will be skipped.
264
264
265
+ # # Per Operation `input` and `output`
266
+
267
+ `input` and `output` attributes can be set on a per operation basis :
268
+
269
+ ` ` ` php
270
+ <?php
271
+ // api/src/Entity/Book.php
272
+
273
+ namespace App\E ntity;
274
+
275
+ use ApiPlatform\C ore\A nnotation\A piResource;
276
+ use App\D to\B ookOutput;
277
+ use App\D to\C reateBook;
278
+ use App\D to\UpdateBoo k;
279
+
280
+ /**
281
+ * @ApiResource(
282
+ * collectionOperations={
283
+ * "create"={
284
+ * "method"="POST",
285
+ * "input"=CreateBook::class,
286
+ * "output"=BookOutput::class
287
+ * }
288
+ * },
289
+ * itemOperations={
290
+ * "update"={
291
+ * "method"="PUT",
292
+ * "input"=UpdateBook::class,
293
+ * "output"=BookOutput::class
294
+ * }
295
+ * }
296
+ * )
297
+ */
298
+ final class Book
299
+ {
300
+ }
301
+ ` ` `
302
+
303
+ Or using XML :
304
+
305
+ ` ` ` xml
306
+ <?xml version="1.0" encoding="UTF-8" ?>
307
+ <!-- api/config/api_platform/resources.xml -->
308
+
309
+ <resources xmlns="https://api-platform.com/schema/metadata"
310
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
311
+ xsi:schemaLocation="https://api-platform.com/schema/metadata
312
+ https://api-platform.com/schema/metadata/metadata-2.0.xsd">
313
+ <resource class="App\E ntity\B ook">
314
+ <collectionOperations>
315
+ <collectionOperation name="create">
316
+ <attribute name="method">POST</attribute>
317
+ <attribute name="input">App\D to\C reateBook</attribute>
318
+ <attribute name="output">App\D to\B ookOutput</attribute>
319
+ </collectionOperation>
320
+ </collectionOperations>
321
+ <itemOperations>
322
+ <itemOperation name="update">
323
+ <attribute name="method">PUT</attribute>
324
+ <attribute name="input">App\D to\UpdateBoo k</attribute>
325
+ <attribute name="output">App\D to\B ookOutput</attribute>
326
+ </itemOperation>
327
+ </itemOperations>
328
+ </resource>
329
+ </resources>
330
+ ` ` `
331
+
332
+ Or using YAML :
333
+
334
+ ` ` ` yaml
335
+ # api/config/api_platform/resources.yaml
336
+ resources:
337
+ App\E ntity\B ook:
338
+ collectionOperations:
339
+ create:
340
+ method: POST,
341
+ input: App\D to\C reateBook,
342
+ output: App\D to\B ookOutput
343
+ itemOperations:
344
+ update:
345
+ method: PUT,
346
+ input: App\D to\UpdateBoo k,
347
+ output: App\D to\B ookOutput
348
+ ` ` `
349
+
265
350
# # Input/Output Metadata
266
351
267
352
When specified, `input` and `output` attributes support :
0 commit comments