NelmioApiDocBundle not generate documentation

2.2k Views Asked by At

I want to use NelmioApiDocBundle for generating documentation automatically. I fallowed standard Symfony doc to install and configure it: https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html. Unfortunately when I go to /api/doc my doc is empty.

I use Symfony 3.4 and NelmioApiDocBundle in v. 3.2.0.

Here is my config:

nelmio_api_doc:
    areas:
        path_patterns: # an array of regexps
            - ^/api(?!/doc$)
        host_patterns:
            - ^api\.
    documentation:
        host: 127.0.0.1
        schemes: [http, https]
        info:
            title: Thanatos API
            description: This is documentation of Thanatos
            version: 1.0.0
        security:
            - Bearer: []

And annotations in my controller (in beginning I want to see any data in my documentation):

/**
 * @Route(
 *  "/",
 *  name="thanatos_dashboard_index", 
 * )
 *
 * @SWG\Response(
 *     response=200,
 *     description="Returns the rewards of an user",
 *     @SWG\Schema(
 *         type="array",
 *         @SWG\Items(ref=@Model(type=Reward::class, groups={"full"}))
 *     )
 * )
 * @SWG\Parameter(
 *     name="order",
 *     in="query",
 *     type="string",
 *     description="The field used to order rewards"
 * )
 * @SWG\Tag(name="rewards")
 * @NelmioSecurity(name="Bearer")
 */
public function indexAction()
{
    return $this->render("@AppThanatos/Dashboard/index.html.twig");
}

In /api/doc I see "No operations defined in spec!". What am I doing wrong?


@UPDATE

I just start to use Sami: http://symfony.com/projects/sami

3

There are 3 best solutions below

2
On

Try this :

Replace

 * @Route(
 *  "/",
 *  name="thanatos_dashboard_index", 
 * )

By

 @Rest\Get("/getVehicles")

And, in your action controller, return array or object like this :

    $em = $this->getDoctrine();
    return $em->getRepository('AppBundle:Vehicle')->findAll();
0
On

I've the same problem. Working on my Mac I have always ERR_EMPTY_RESPONSE (using Chrome) but in the production environment the same configuration works fine.

The only difference was Xdebug, I've tried disabling the module and now everything works.

0
On

The assets normally are installed by composer if any command event (usually post-install-cmd or post-update-cmd) triggers the ScriptHandler::installAssets script. If you have not set up this script, you can manually execute this command:

php bin/console assets:install --symlink