@@ -189,9 +189,8 @@ resources:
189
189
` ` ` xml
190
190
<?xml version="1.0" encoding="UTF-8" ?>
191
191
<resources xmlns="https://api-platform.com/schema/metadata"
192
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
193
- xsi:schemaLocation="https://api-platform.com/schema/metadata
194
- https://api-platform.com/schema/metadata/metadata-2.0.xsd">
192
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
193
+ xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd">
195
194
<resource class="App\Entity\Product">
196
195
<property name="name">
197
196
<attribute name="openapi_context">
@@ -311,58 +310,96 @@ You also have full control over both built-in and custom operations documentatio
311
310
312
311
[ codeSelector]
313
312
313
+ ``` php
314
+ <?php
315
+ // api/src/Entity/Rabbit.php
316
+
317
+ use ApiPlatform\Core\Annotation\ApiProperty;
318
+ use ApiPlatform\Core\Annotation\ApiResource;
319
+ use App\Controller\RandomRabbit;
320
+
321
+ #[ApiResource(collectionOperations: [
322
+ 'create_rabbit' => [
323
+ 'method' => 'post',
324
+ 'path' => '/rabbit/create',
325
+ 'controller' => RandomRabbit::class,
326
+ 'openapi_context' => [
327
+ 'summary' => 'Create a rabbit picture',
328
+ 'description' => "# Pop a great rabbit picture by color!\n\n",
329
+ 'requestBody' => [
330
+ 'content' => [
331
+ 'application/json' => [
332
+ 'schema' => [
333
+ 'type' => 'object',
334
+ 'properties' =>
335
+ [
336
+ 'name' => ['type' => 'string'],
337
+ 'description' => ['type' => 'string'],
338
+ ],
339
+ ],
340
+ 'example' => [
341
+ 'name' => 'Mr. Rabbit',
342
+ 'description' => 'Pink Rabbit',
343
+ ],
344
+ ],
345
+ ],
346
+ ],
347
+ ],
348
+ ],
349
+ ]
350
+ )]
351
+ class Rabbit
352
+ {}
353
+ ```
354
+
314
355
``` yaml
315
356
resources :
316
357
App\Entity\Rabbit :
317
358
collectionOperations :
318
- create_user :
319
- method : get
320
- path : ' /rabbit/rand '
359
+ create_rabbit :
360
+ method : post
361
+ path : ' /rabbit/create '
321
362
controller : App\Controller\RandomRabbit
322
- # if you are using OpenApi V2 (Swagger) use 'swagger_context' instead of 'openapi_context'
323
363
openapi_context :
324
364
summary : Random rabbit picture
325
365
description : >
326
366
# Pop a great rabbit picture by color!
327
367
328
368

329
369
330
- parameters :
331
- -
332
- in : body
333
- schema :
334
- type : object
335
- properties :
336
- name : {type: string}
337
- description : {type: string}
338
- example :
339
- name : Rabbit
340
- description : Pink rabbit
370
+ requestBody :
371
+ content :
372
+ application/json :
373
+ schema :
374
+ type : object
375
+ properties :
376
+ name : { type: string }
377
+ description : { type: string }
378
+ example :
379
+ name : Mr. Rabbit
380
+ description : Pink rabbit
381
+
341
382
```
342
383
343
384
``` xml
344
385
<?xml version =" 1.0" encoding =" UTF-8" ?>
345
386
<resources xmlns =" https://api-platform.com/schema/metadata"
346
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
347
- xsi:schemaLocation="https://api-platform.com/schema/metadata
387
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
388
+ xsi : schemaLocation =" https://api-platform.com/schema/metadata
348
389
https://api-platform.com/schema/metadata/metadata-2.0.xsd" >
349
390
<resource class =" App\Entity\Rabbit" >
350
391
<collectionOperations >
351
- <collectionOperation name="create_user ">
352
- <attribute name="method">get </attribute>
353
- <attribute name="path">/rabbit/rand </attribute>
392
+ <collectionOperation name =" create_rabbit " >
393
+ <attribute name =" path " >/rabbit/create </attribute >
394
+ <attribute name =" method " >post </attribute >
354
395
<attribute name =" controller" >App\Controller\RandomRabbit</attribute >
355
- <!-- if you are using OpenApi V2 (Swagger) use 'swagger_context' instead of 'openapi_context' -->
356
396
<attribute name =" openapi_context" >
357
- <attribute name="summary">Random rabbit picture</attribute>
358
- <attribute name="description">
359
- # Pop a great rabbit picture by color!
397
+ <attribute name =" summary" >Create a rabbit picture </attribute >
398
+ <attribute name =" description" ># Pop a great rabbit picture by color!!
360
399
361
- 
362
- </attribute>
363
- <attribute name="parameters">
364
- <attribute>
365
- <attribute name="in">body</attribute>
400
+ </attribute >
401
+ <attribute name =" content" >
402
+ <attribute name =" application/json" >
366
403
<attribute name =" schema" >
367
404
<attribute name =" type" >object</attribute >
368
405
<attribute name =" properties" >
@@ -374,10 +411,6 @@ resources:
374
411
</attribute >
375
412
</attribute >
376
413
</attribute >
377
- <attribute name="example">
378
- <attribute name="name">Rabbit</attribute>
379
- <attribute name="description">Pink rabbit</attribute>
380
- </attribute>
381
414
</attribute >
382
415
</attribute >
383
416
</attribute >
0 commit comments