FriendsOfSymfony / FOSRestBundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony
http://symfony.com/doc/master/bundles/FOSRestBundle/index.html
MIT License
2.79k stars 707 forks source link

FOSRest\View group overload when forwarding to controller #2335

Open flohw opened 2 years ago

flohw commented 2 years ago

Hi!

I notice that when a controller forward its request to another the @FOSRest\View annotation is overloaded by the latest instead of the annotation on the controller which forward the request. I think the good option would be that the forwarding controller should override the latest.

An example to clarify


namespace Backend\Controller;

/**
 * @FOSRest\View(serializerGroups={"backend_list"})
 */
class GetNewsController {
    public function __invoke() {
        return $this->forward(Frontend\Controller\GetNewsController::class);
    }
}

namespace Frontend\Controller;

/**
 * @FOSRest\View(serializerGroups={"frontend_list"})
 */
class GetNewsController {
    public function __invoke() {
        return [];
    }
}

When the Frontend controller is called, the applied serializer groups are those one listed in Backend. Which might be a problem.

I can try to investigate and make a PR if I can get some clues where to search :slightly_smiling_face:

Thanks