gondor
gondor

Reputation: 93

NelmioApiDocBundle doesn't work "No operations defined in spec!"

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",

Upvotes: 4

Views: 4322

Answers (3)

shuba.ivan
shuba.ivan

Reputation: 4061

Just remove

host_patterns:
    - ^api\.

and set your virtual host in

documentation:
  host: symfony.localhost

Upvotes: 3

nicolae-stelian
nicolae-stelian

Reputation: 344

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/ ]

Upvotes: 0

Christian Paredes
Christian Paredes

Reputation: 21

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

Upvotes: 2

Related Questions