Hi!
I'm currently trying to implement NelmioApiDocBundle in my Symfony 3.4 project. I carefully read the documentation but event after that I'm not able to figure how to make this bundle work.
When I go to http://localhost:8000/app_dev.php/api/doc, I got an empty page with only "No operations defined in spec!". After reading the others issues about this problem, I tried to install the assets (php bin/console assets:install --symlink) but it doesn't change anything.
Here is my controller (only the begginning):
`
namespace AppBundle\Controller;
use FOS\RestBundle\Request\ParamFetcher;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use FOS\RestBundle\Controller\Annotations\Get;
use Nelmio\ApiDocBundle\Annotation\Model;
use Nelmio\ApiDocBundle\Annotation\Security;
use Swagger\Annotations as SWG;
class ApiController extends Controller
{
/**
* Return a collection of sheets matching the provided arguments
* eg. ?queries[]=test&queries[]=test2
*
* @Get("/api/sheets")
*
* @SWG\Response(
* response=200,
* description="Return a collection of sheets matching the provided arguments",
* @SWG\Property(
* @SWG\Items(ref=@Model(type=Sheet::class))
* )
* )
*
* @QueryParam(name="queries", nullable=true)
* @QueryParam(name="tags", nullable=true)
* @QueryParam(name="types", nullable=true)
* @QueryParam(name="editors", nullable=true)
* @QueryParam(name="start_year", nullable=true)
* @QueryParam(name="end_year", nullable=true)
* @QueryParam(name="catalogs", nullable=true)
*
* @param ParamFetcher $paramFetcher
*
* @return JsonResponse
*/
public function fetchSheetsAction(ParamFetcher $paramFetcher)
{
$queries = $paramFetcher->get('queries');
$tags = $paramFetcher->get('tags');
$types = $paramFetcher->get('types');
$editors = $paramFetcher->get('editors');
$startYear = $paramFetcher->get('start_year');
$endYear = $paramFetcher->get('end_year');
$catalogs = $paramFetcher->get('catalogs');
$queryBuilder = $this->get('doctrine.orm.entity_manager')->createQueryBuilder();`
Thanks for your help
Okay, I figured part of the problem here.
I simply tried removing the following code from my config.yml (this code is from the doc of the bundle):
nelmio_api_doc:
areas:
path_patterns: # an array of regexps
- ^/api(?!/doc$)
host_patterns:
- ^api\.
After removing that part, I got a full list of documentation about various route. Then I removed the host_patterns part and I got my documentation.
areas:
path_patterns: # an array of regexps
- ^/api(?!/doc$)
I can't really figure out why, but it seem to work like that.
I have to say that this bundle lack of documentation, you can maybe add a full list of the various provided annotations and associated use cases with explanations, not just an example.
I don't think this should have been added to the docs here indeed, this is the first thing users see and it's not something everyone uses (it's not shipped with our flex recipe btw; host_patterns applies a regex on the host domain and only documents matching routes).
FYI this was added in https://github.com/nelmio/NelmioApiDocBundle/pull/1257.
I have to say that this bundle lack of documentation, you can maybe add a full list of the various provided annotations and associated use cases with explanations, not just an example.
They're described in zircote/swagger-php docs, this should be more visible though that's true. PR welcome if you're willing to do this change :)
Most helpful comment
Okay, I figured part of the problem here.
I simply tried removing the following code from my config.yml (this code is from the doc of the bundle):
nelmio_api_doc: areas: path_patterns: # an array of regexps - ^/api(?!/doc$) host_patterns: - ^api\.After removing that part, I got a full list of documentation about various route. Then I removed the host_patterns part and I got my documentation.
areas: path_patterns: # an array of regexps - ^/api(?!/doc$)I can't really figure out why, but it seem to work like that.
I have to say that this bundle lack of documentation, you can maybe add a full list of the various provided annotations and associated use cases with explanations, not just an example.