Provide example for action summary and description

This commit is contained in:
David Buchmann 2018-01-09 10:31:38 +01:00 committed by GitHub
parent 393a6c061e
commit c30fb4c984
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
NelmioApiDocBundle NelmioApiDocBundle
================== ==================
The **NelmioApiDocBundle** bundle allows you to generate documentation in the The **NelmioApiDocBundle** bundle allows you to generate documentation in the
OpenAPI (Swagger) format and provides a sandbox to interactively browse the API documentation. OpenAPI (Swagger) format and provides a sandbox to interactively browse the API documentation.
@ -12,7 +12,7 @@ This bundle supports _Symfony_ route requirements, PHP annotations,
[_FOSRestBundle_](https://github.com/FriendsOfSymfony/FOSRestBundle) annotations [_FOSRestBundle_](https://github.com/FriendsOfSymfony/FOSRestBundle) annotations
and apps using [_Api-Platform_](https://github.com/api-platform/api-platform). and apps using [_Api-Platform_](https://github.com/api-platform/api-platform).
For models, it supports the Symfony serializer and the JMS serializer. For models, it supports the Symfony serializer and the JMS serializer.
Migrate from 2.x to 3.0 Migrate from 2.x to 3.0
----------------------- -----------------------
@ -21,8 +21,8 @@ Migrate from 2.x to 3.0
Installation Installation
------------ ------------
Open a command console, enter your project directory and execute the following command to download the latest version of this bundle: Open a command console, enter your project directory and execute the following command to download the latest version of this bundle:
.. code-block:: bash .. code-block:: bash
@ -65,7 +65,7 @@ Open a command console, enter your project directory and execute the following c
path: /api/doc.json path: /api/doc.json
methods: GET methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger } defaults: { _controller: nelmio_api_doc.controller.swagger }
As you just installed the bundle, you'll likely see routes you don't want in As you just installed the bundle, you'll likely see routes you don't want in
your documentation such as `/_profiler/`. To fix this, you can filter the your documentation such as `/_profiler/`. To fix this, you can filter the
routes that are documented by configuring the bundle: routes that are documented by configuring the bundle:
@ -79,7 +79,7 @@ Open a command console, enter your project directory and execute the following c
- ^/api(?!/doc$) - ^/api(?!/doc$)
How does this bundle work? How does this bundle work?
-------------------------- --------------------------
It generates you a swagger documentation from your symfony app thanks to It generates you a swagger documentation from your symfony app thanks to
_Describers_. Each of these _Describers_ extract infos from various sources. _Describers_. Each of these _Describers_ extract infos from various sources.
@ -88,11 +88,11 @@ routes, etc.
If you configured the ``app.swagger_ui`` route above, you can browse your If you configured the ``app.swagger_ui`` route above, you can browse your
documentation at `http://example.org/api/doc`. documentation at `http://example.org/api/doc`.
Using the bundle Using the bundle
---------------- ----------------
You can configure global information in the bundle configuration ``documentation.info`` section (take a look at You can configure global information in the bundle configuration ``documentation.info`` section (take a look at
[the Swagger specification](http://swagger.io/specification/) to know the fields [the Swagger specification](http://swagger.io/specification/) to know the fields
available): available):
@ -123,6 +123,10 @@ To document your routes, you can use the SwaggerPHP annotations and the
class UserController class UserController
{ {
/* /*
* List the rewards of the specified user.
*
* This call takes into account all confirmed awards, but not pending or refused awards.
*
* @Route("/api/{user}/rewards", methods={"GET"}) * @Route("/api/{user}/rewards", methods={"GET"})
* @SWG\Response( * @SWG\Response(
* response=200, * response=200,
@ -146,12 +150,14 @@ To document your routes, you can use the SwaggerPHP annotations and the
} }
} }
The normal PHP docblock for the controller method is used for the summary and description.
Use models Use models
---------- ----------
As shown in the example above, the bundle provides the ``@Model`` annotation. As shown in the example above, the bundle provides the ``@Model`` annotation.
When you use it, the bundle will deduce your model properties. When you use it, the bundle will deduce your model properties.
It has two options: It has two options:
* ``type`` to specify your model's type:: * ``type`` to specify your model's type::
@ -165,12 +171,12 @@ It has two options:
/** /**
* @Model(type=User::class, groups={"non_sensitive_data"}) * @Model(type=User::class, groups={"non_sensitive_data"})
*/ */
.. warning:: .. warning::
The ``@Model`` annotation acts like a ``@Schema`` annotation. If you nest it with a ``@Schema`` annotation, the bundle will consider that The ``@Model`` annotation acts like a ``@Schema`` annotation. If you nest it with a ``@Schema`` annotation, the bundle will consider that
you're documenting an array of models. you're documenting an array of models.
For instance, the following example:: For instance, the following example::
/** /**
@ -215,7 +221,7 @@ It has two options:
public function myAction() public function myAction()
{ {
} }
If you're not using the JMS Serializer If you're not using the JMS Serializer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -249,4 +255,4 @@ If you need more complex features, take a look at:
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
areas areas