SonataUserBundle: Getting errors because of API code bundle needs

Hey,

I have "sonata-project/user-bundle": "^2.2" in my composer.json. I do not plan to use any type of API component. When I do composer update I get this:

[Doctrine\Common\Annotations\AnnotationException]
  [Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction() does not exist, or could not be auto-loaded.


Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the post-update-cmd event terminated with an exception



  [RuntimeException]
  An error occurred when executing the "'cache:clear --no-warmup'" command:

    [Doctrine\Common\Annotations\AnnotationException]
    [Semantical Error] The annotation "@Nelmio\ApiDocBundle\Annotation\ApiDoc" in method Sonata\UserBundle\Controller\Api\GroupController::getGroupsAction() does not exist, or could not be auto-loaded.

  .

Do I need to install & configure FOSRestBundle and NelmioApiDocBundle? Is this something that you are forcing users to do???

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 16 (13 by maintainers)

Most upvoted comments

I have the same problem: using JMSDiExtraBundle without NelmioApiDocBundle.

Maybe the problem relies in the cache warmer scanning all bundles folders and looking for controllers (note that all_bundles: false is ignored).

It works if you disable the warmer:

jms_di_extra:
    cache_warmer:
        enabled: false

There is a blacklist option but it relies on the controller realpath.

What about prepending the blacklist option if JMSDiExtraBundle is found but NelmioApiDocBundle not?

Edit: I made a quick test with the following prepended configuration and it seems to work just fine (other sonata bundles have the same issue, like SonataClassificationBundle). I can work on a PR.

public function prepend(ContainerBuilder $container)
{
    $bundles = $container->getParameter('kernel.bundles');
    if (isset($bundles['JMSDiExtraBundle']) &&
        (!isset($bundles['NelmioApiDocBundle']) || !isset($bundles['FOSRestBundle']))) {
        $blacklistedControllers = [];
        foreach (glob(__DIR__.'/../Controller/Api/*.php', GLOB_NOSORT) as $filename) {
            $blacklistedControllers[] = realpath($filename);
        }

        if (!empty($blacklistedControllers)) {
            $container->prependExtensionConfig('jms_di_extra', [
                'cache_warmer' => [
                    'controller_file_blacklist' => $blacklistedControllers,
                ],
            ]);
        }
    }
}