4
votes

I want to use nelmio for symfony-project, but it doesn't work.

It always says: No operations defined in spec!

I also try the example on https://symfony.com/doc/current/bundles/NelmioApiDocBundle/index.html

Whats's wrong? Any ideas?

routing.yml

app.swagger_ui:
    path: /api/doc
    methods: GET
    defaults: { _controller: nelmio_api_doc.controller.swagger_ui }

config.yml

nelmio_api_doc:
    areas:
        path_patterns: # an array of regexps
        - ^/api(?!/doc$)
        host_patterns:
        - ^api\.

Controller

/**
 * @Route("/api/test", methods={"GET"})
 * @SWG\Response(
 *     response=200,
 *     description="Returns the rewards of an user"
 * )
 * @SWG\Parameter(
 *     name="order",
 *     in="query",
 *     type="string",
 *     description="The field used to order rewards"
 * )
 */
public function testAction()
{

}   

composer.json

"symfony/symfony": "3.4.*",
"nelmio/api-doc-bundle": "3.2.1",
3
I'm having the same issue, did you figure it out?h00ligan

3 Answers

3
votes

Just remove

host_patterns:
    - ^api\.

and set your virtual host in

documentation:
  host: symfony.localhost
2
votes

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

0
votes

The problem is in config.yml path patterns. If you remove the config(all nelmio_api_doc) or change the path patterns will work. Example:

nelmio_api_doc:
    areas:
        default:
            path_patterns: [ /api/ ]