Skip to content

Update "Changing Operations [...]" section #1284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 69 additions & 36 deletions core/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ resources:
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata https://api-platform.com/schema/metadata/metadata-2.0.xsd">
<resource class="App\Entity\Product">
<property name="name">
<attribute name="openapi_context">
Expand Down Expand Up @@ -311,58 +310,96 @@ You also have full control over both built-in and custom operations documentatio

[codeSelector]

```php
<?php
// api/src/Entity/Rabbit.php

use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Controller\RandomRabbit;

#[ApiResource(collectionOperations: [
'create_rabbit' => [
'method' => 'post',
'path' => '/rabbit/create',
'controller' => RandomRabbit::class,
'openapi_context' => [
'summary' => 'Create a rabbit picture',
'description' => "# Pop a great rabbit picture by color!\n\n![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg)",
'requestBody' => [
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' =>
[
'name' => ['type' => 'string'],
'description' => ['type' => 'string'],
],
],
'example' => [
'name' => 'Mr. Rabbit',
'description' => 'Pink Rabbit',
],
],
],
],
],
],
]
)]
class Rabbit
{}
```

```yaml
resources:
App\Entity\Rabbit:
collectionOperations:
create_user:
method: get
path: '/rabbit/rand'
create_rabbit:
method: post
path: '/rabbit/create'
controller: App\Controller\RandomRabbit
# if you are using OpenApi V2 (Swagger) use 'swagger_context' instead of 'openapi_context'
openapi_context:
summary: Random rabbit picture
description: >
# Pop a great rabbit picture by color!

![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg)

parameters:
-
in: body
schema:
type: object
properties:
name: {type: string}
description: {type: string}
example:
name: Rabbit
description: Pink rabbit
requestBody:
content:
application/json:
schema:
type: object
properties:
name: { type: string }
description: { type: string }
example:
name: Mr. Rabbit
description: Pink rabbit

```

```xml
<?xml version="1.0" encoding="UTF-8" ?>
<resources xmlns="https://api-platform.com/schema/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://api-platform.com/schema/metadata
https://api-platform.com/schema/metadata/metadata-2.0.xsd">
<resource class="App\Entity\Rabbit">
<collectionOperations>
<collectionOperation name="create_user">
<attribute name="method">get</attribute>
<attribute name="path">/rabbit/rand</attribute>
<collectionOperation name="create_rabbit">
<attribute name="path">/rabbit/create</attribute>
<attribute name="method">post</attribute>
<attribute name="controller">App\Controller\RandomRabbit</attribute>
<!-- if you are using OpenApi V2 (Swagger) use 'swagger_context' instead of 'openapi_context' -->
<attribute name="openapi_context">
<attribute name="summary">Random rabbit picture</attribute>
<attribute name="description">
# Pop a great rabbit picture by color!
<attribute name="summary">Create a rabbit picture </attribute>
<attribute name="description"># Pop a great rabbit picture by color!!

![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg)
</attribute>
<attribute name="parameters">
<attribute>
<attribute name="in">body</attribute>
![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg)</attribute>
<attribute name="content">
<attribute name="application/json">
<attribute name="schema">
<attribute name="type">object</attribute>
<attribute name="properties">
Expand All @@ -374,10 +411,6 @@ resources:
</attribute>
</attribute>
</attribute>
<attribute name="example">
<attribute name="name">Rabbit</attribute>
<attribute name="description">Pink rabbit</attribute>
</attribute>
</attribute>
</attribute>
</attribute>
Expand Down
Binary file modified distribution/images/swagger-ui-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.