FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

No @QueryParam/@RequestParam configuration

Open andrius-kulbis opened this issue 12 years ago • 10 comments

My action in controller:

/*
 * @REST\QueryParam(name="page", requirements="\d+", default="1", description="page number")
 * @REST\QueryParam(name="pageSize", requirements="\d+", default="25", description="users per page")
 * @REST\View()
 */
public function allAction(ParamFetcher $paramFetcher) 
{
        $pageSize = $paramFetcher->get('pageSize');
        $page = $paramFetcher->get('page');

        $users = $this->get('backend.user.handler')->all($pageSize, $pageSize * $page - 1);

        return $users;
}

The config of FOSRestBundle:

fos_rest:
   param_fetcher_listener: true
   body_listener: true
   format_listener: false
   view:
        view_response_listener: 'force'

And the routing for this route:

backend_get_all_users:
    pattern:     /users
    defaults: { _controller: MyBackendBundle:User:all, _format: json }
    requirements:
        _method: GET

When I try to visit this route I get

No @QueryParam/@RequestParam configuration for parameter 'pageSize'

What am I missing?

andrius-kulbis avatar Oct 10 '14 10:10 andrius-kulbis

hmm I do not see anything wrong from a quick look either. Did you clear your cache?

lsmith77 avatar Oct 10 '14 11:10 lsmith77

Yes the cache is cleared but still I get that error in both the prod and dev environments.

andrius-kulbis avatar Oct 10 '14 11:10 andrius-kulbis

does it work with page ?

lsmith77 avatar Oct 10 '14 11:10 lsmith77

No , if i remove $pageSize = $paramFetcher->get('pageSize'), I get

No @QueryParam/@RequestParam configuration for parameter 'page'

andrius-kulbis avatar Oct 10 '14 11:10 andrius-kulbis

I assume you have use FOS\RestBundle\Controller\Annotations as REST; in your code? if so .. I fear you will have to debug this inside the ParamFetcher (and the ParamFetcherReader) or try to reproduce the issue inside https://github.com/gimler/symfony-rest-edition and send me a PR with the test case.

lsmith77 avatar Oct 10 '14 12:10 lsmith77

Well, HERE I get emty array, after reading the params.

andrius-kulbis avatar Oct 10 '14 12:10 andrius-kulbis

ok then the issue is in the ParamReader

lsmith77 avatar Oct 10 '14 13:10 lsmith77

Found the problem, nooby problem.

There was /* instead of /** in method comment section.

andrius-kulbis avatar Oct 13 '14 09:10 andrius-kulbis

I ran into a similar problem and it was also because and invalid comment in the comments section

jcornide avatar Apr 29 '17 19:04 jcornide

In my case it was a whitespace in the fetcher parameter string

FullStackAlex avatar May 19 '18 02:05 FullStackAlex