/**
  * @param ApiResource $apiResource
  * @param RouteCollection $routes
  * @param ApiResource $parentResource
  */
 private function addRoute(ApiResource $apiResource, RouteCollection $routes, $parentResource = null)
 {
     foreach ($apiResource->getActions() as $action) {
         if (!$parentResource && !$apiResource->isMainResource()) {
             continue;
         }
         $route = new Route($this->getUrl($action, $parentResource));
         $route->setDefault('_api_resource', $apiResource->getName())->setDefault('_controller', $action->getControllerAction())->setDefault('_entity', $apiResource->getEntityClass())->setDefault('_security', $this->expressionsToSecurity($action->getSecurityExpression()))->setDefault('_identifier', $apiResource->getIdentifier())->setMethods($action->getMethods());
         if ($action instanceof Index) {
             $route->setDefault('_indexGetterMethod', $action->getResourceGetterMethod());
             $route->setDefault('_limit', $action->getDefaultLimit());
         }
         $routes->add($action->getRouteName($parentResource), $route);
     }
     foreach ($apiResource->getSubResources() as $subResource) {
         $this->addRoute($subResource, $routes, $apiResource);
     }
 }