FOSRestBundle "Some mandatory parameters are missing (id)" with route parameters

762 Views Asked by At

I'm using Symfony 2.7.3 with FOSRestBundle to build one REST api. My model has user and has tickets. User can have tickets and I want to fetch user tickets by calling /user/{id}/tickets endpoints. My api has page and limit query parameters. I'm using param_fetch_listener: force to have my method parameters injected. I'm trying to mix route parametes and query parameters and I'm getting the error "Some mandatory parameters are missing (id)". My method anotations are:

  /**
 * @Get("/users/{id}/tickets")
 * @ApiDoc(
 *   resource = true
 * )
 *
 * @QueryParam(name="page", requirements="\d+")
 * @QueryParam(name="limit", requirements="\d+")
 */
public function getUsersTicketsAction($id, $page, $limit) {
    // my code
}

When I reach the endpoint I'm getting the error: "Some mandatory parameters are missing (\"id\") to generate a URL for route \"api_1_get_users_tickets\".". Any ideas on how to solve it? Thanks!


EDIT: the code above is working fine. The error message is related to some code I had inside // my code. I tried my method with empty return and it worked. I was missing my id inside some internal logic. Sorry for the confusion. I'll think about closing this issue or maybe keeping it here for future reference. Thanks!

0

There are 0 best solutions below