2017-05-13 17:21:28 +02:00
2017-03-16 19:52:18 +01:00
2017-05-13 13:55:13 +02:00
2017-03-17 19:37:51 +01:00
2017-03-17 19:37:51 +01:00
2016-12-29 12:09:26 +01:00
2017-03-16 19:52:18 +01:00
2017-01-25 18:44:57 +01:00
2017-03-15 13:38:23 +01:00
2016-07-30 20:04:03 +02:00
2017-03-15 13:38:23 +01:00
2017-01-14 17:36:56 +01:00
2017-05-13 13:55:13 +02:00
2017-05-13 17:21:28 +02:00
2016-12-29 12:09:26 +01:00
2017-01-14 17:36:56 +01:00
2017-03-15 13:38:23 +01:00
2016-07-12 00:33:55 +02:00
2017-05-13 17:21:28 +02:00
2017-05-13 13:55:13 +02:00
2017-01-09 12:21:53 +01:00

NelmioApiDocBundle

Build
Status Total Downloads Latest Stable
Version

The NelmioApiDocBundle bundle allows you to generate a decent documentation for your APIs.

Installation

First, open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require nelmio/api-doc-bundle dev-dev

Then add the bundle to your kernel:

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...

            new Nelmio\ApiDocBundle\NelmioApiDocBundle(),
        ];

        // ...
    }
}

To access your documentation in your browser, register the following route:

NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing/swaggerui.xml"
    prefix:   /api/doc

What does this bundle?

It generates you a swagger documentation from your symfony app thanks to Describers. Each of this Describers extract infos from various sources. For instance, one extract data from SwaggerPHP annotations, one from your routes, etc.

If you configured the route above, you can browse your documentation at http://example.org/api/doc.

Configure the bundle

If 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 routes that are documented by configuring the bundle:

# app/config/config.yml
nelmio_api_doc:
    routes:
        path_patterns: # an array of regexps
            - ^/api

Use the bundle

You can configure globally your documentation in the config (take a look at the Swagger specification to know the fields available):

nelmio_api_doc:
    documentation:
        info:
            title: My App
            description: This is an awesome app!
            version: 1.0.0

To document your routes, you can use annotations in your controllers:

use AppBundle\Entity\User;
use AppBundle\Entity\Reward;
use Nelmio\ApiDocBundle\Annotation\Model;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Swagger\Annotations as SWG;

class DefaultController
{
    /*
     * @Route("/api/{user}/rewards", methods={"GET"})
     * @SWG\Response(
     *     response=200,
     *     description="Returns the rewards of an user",
     *     @SWG\Schema(
     *         type="array",
     *         @Model(type=Reward::class)
     *     )
     * )
     * @SWG\Parameter(
     *     name="order",
     *     in="query",
     *     type="string",
     *     description="The field used to order rewards"
     * )
     * @SWG\Tag(name="rewards")
     */
    public function indexAction(User $user)
    {
        // ...
    }
}

What's supported?

This bundle supports Symfony route requirements, PHP annotations, Swagger-Php annotations, FOSRestBundle annotations and apps using Api-Platform.

It supports models through the @Model annotation.

Contributing

See CONTRIBUTING file.

Running the Tests

Install the Composer dependencies:

git clone https://github.com/nelmio/NelmioApiDocBundle.git
cd NelmioApiDocBundle
composer update

Then run the test suite:

./phpunit

License

This bundle is released under the MIT license.

Description
Generates documentation for your REST API from annotations
Readme 17 MiB
Languages
PHP 86.4%
Twig 11%
CSS 2.5%