composer create-project symfony/skeleton restapi
cd restapi
composer require nelmio/api-doc-bundle
In Kernel:
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
];
In routing:
app.swagger_ui:
path: /api/doc
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
app.swagger:
path: /api/doc.json
methods: GET
defaults: { _controller: nelmio_api_doc.controller.swagger }
I open http://localhost:8000/api/doc and see:
(1/1) LogicException Controller not found: service "nelmio_api_doc.controller.swagger_ui" does not exist.
--
in ContainerControllerResolver.php (line 75)
at ContainerControllerResolver->createController('nelmio_api_doc.controller.swagger_ui')in ControllerResolver.php (line 43)
at ControllerResolver->createController('nelmio_api_doc.controller.swagger_ui')in ControllerResolver.php (line 69)
at ControllerResolver->getController(object(Request))in ContainerControllerResolver.php (line 41)
at ContainerControllerResolver->getController(object(Request))in HttpKernel.php (line 132)
at HttpKernel->handleRaw(object(Request), 1)in HttpKernel.php (line 66)
at HttpKernel->handle(object(Request), 1, true)in Kernel.php (line 190)
at Kernel->handle(object(Request))in index.php (line 37)
But it http://localhost:8000/api/doc.json works fine!
Twig and assets packages are needed to use swagger ui.
Thank you. Problem solved:
composer require symfony/twig-bundle
composer require symfony/asset
Ok, closing then :)
@GuilhemN if symfony/twig-bundle and symfony/asset are required to use the Swagger ui, you should update the recipe https://github.com/symfony/recipes-contrib/blob/master/nelmio/api-doc-bundle/3.0/config/routes/nelmio_api_doc.yaml
to not include the Swagger Ui by default or add the dependencies in composer.json
Indeed it feels strange that the "default" loaded route have additional requirements and the one commented works out of the box.
I would inverse the two comments.
If you feel this is the right change, you can give your input in this repice : https://github.com/symfony/recipes-contrib/pull/340
sooooooo it still does not work, and the bundle documentation https://symfony.com/doc/4.x/bundles/NelmioApiDocBundle/index.html says ZERO about the requirement of symfony/twig-bundle and symfony/asset
@GuilhemN why did you set the ticket to closed without actually fixing the problem (without updating the docs, saying these two bundles are required, or the recipe, by requesting these two bundles as dependencies)? do you think this is an adequate solution to a problem?
@magnetik how does your commit fix the problem? did you really test that the bundle actually work if there's no twig and asset bundles installed initially?
Those are a requirement only if you want to use the swagger UI.
It's written in the recipe and it's not a requirement for the rest of the bundle (it's working by default as the UI is disabled).
We could add a note about this in the docs when we talk about the swagger UI route to be even clearer I guess. PR welcome if you'd like to do the change.
No, the documentation level of problem fix won't work. It's a crutch, not a fix. If I enable the Swagger UI and I miss the required dependencies, I must get the error message saying I'm missing these required dependencies.
You know putting thumbs down on my messages and writing with a strong tone is not really constructive nor motivating me to dedicate time to do the change.
I'm very busy and this is not my priority. Having a clearer error would be great but it hasn't been done because no one found time to dedicate it so far.
I guess the easiest solution would be to add a dummy controller when the dependencies are not respected (here: https://github.com/nelmio/NelmioApiDocBundle/blob/a7573897fb6cd6fcd10f90c57eee1069e6340e96/DependencyInjection/NelmioApiDocExtension.php#L156) and this controller would just throw an error at runtime when it is accessed. PR welcome if someone wants to contribute this.
Most helpful comment
Thank you. Problem solved: