Skip to content

Commit 0a5b417

Browse files
Rodrigue Villetarddunglas
authored andcommitted
[swagger] - add operation swagger_context example. (#444)
* [swagger] - add operation `swagger_context` example. * Update swagger.md
1 parent 58dc2d2 commit 0a5b417

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

core/operations.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ App\Entity\Book:
172172
color: 'brown'
173173
host: '{subdomain}.api-platform.com'
174174
schemes: ['https']
175-
options:
175+
options:
176176
my_option: 'my_option_value'
177177
put:
178178
method: 'PUT'
@@ -489,6 +489,8 @@ The `special` operation reference the Symfony route named `book_special`.
489489
Note: By default, API Platform uses the first `GET` operation defined in `collectionOperations` to generate the IRI for
490490
a resource class.
491491

492+
Note: With custom operation, you will probably want to properly document it. See the [swagger](swagger.md) part of the documentation to do so.
493+
492494
### Recommended Method
493495

494496
First, let's create your custom operation:

core/swagger.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,32 @@ class User
225225
}
226226
```
227227

228+
## Changing Operations in the Swagger Documentation
229+
230+
You also have full control over both built-in and custom operations documentation:
231+
232+
```yaml
233+
resources:
234+
App\Entity\Rabbit:
235+
collectionOperations:
236+
create_user:
237+
method: get
238+
path: '/rabbit/rand'
239+
controller: App\Controller\RandomRabbit
240+
swagger_context:
241+
summary: Random rabbit picture
242+
description: >
243+
# Pop a great rabbit picture by color!
244+
245+
![A great rabbit](https://rabbit.org/graphics/fun/netbunnies/jellybean1-brennan1.jpg)
246+
247+
requestBody: '{"days": 23}'
248+
parameters:
249+
- {name: 'theme', description: 'dark'}
250+
```
251+
252+
![Impact on swagger ui](../distribution/images/swagger-ui-2.png)
253+
228254
## Changing the Swagger UI Location
229255
230256
Sometimes you may want to have the API at one location, and the Swagger UI at a different location. This can be done by disabling the Swagger UI from the API Platform configuration file and manually adding the Swagger UI controller.

distribution/images/swagger-ui-2.png

43.3 KB
Loading

0 commit comments

Comments
 (0)