FOSRestBundle icon indicating copy to clipboard operation
FOSRestBundle copied to clipboard

@QueryParam default value from the PHP code directly

Open dewos opened this issue 12 years ago • 7 comments

Like Symfony. see http://symfony.com/blog/new-in-symfony-2-2-small-things-matter

dewos avatar Apr 02 '13 21:04 dewos

can you try and implement this?

lsmith77 avatar Apr 03 '13 13:04 lsmith77

Sorry, not now. I'm overloaded with work.

dewos avatar Apr 06 '13 22:04 dewos

The problem is a bit deeper I think. If I have something like:

    /**
     * @Rest\QueryParam(name="page",  requirements="\d+", default="1", description="Page of the overview")
     * @Rest\QueryParam(name="limit", requirements="\d+", default="25", description="Limit per page")
     */
    public function indexAction($page = 1, $limit = 25)

and set param_fetcher_listener to force I'm getting an exception from:

FOS/RestBundle/EventListener/ParamFetcherListener.php at line 64 with the message: ParamFetcher parameter conflicts with a path parameter 'page' for route 'api_model_index'"

If I remove the defaults from the method-signature, everything is working fine. So we have a conflct between ParamFetcher from FOSRest and ParamConverter from SensioExtraBundle.

I would be happy to provide a patch, but I'm unsure what`s the intended behavior would be. The simplest (and imho propably best) solution would be, to simple remove the Exception from ParamFetcherListener and document the behaviour, that if both Listeners are used, the ParamConverter takes precedence.

benbender avatar Apr 21 '13 09:04 benbender

i dont really use either of the features in any project, so its hard for me to tell what the best direction is ..

lsmith77 avatar Apr 21 '13 10:04 lsmith77

As I thought a bit more about this topic, it became clear, that the problem is more or less conceptional. The root-problem is that the force-option copies content from one "context" (in symfony terms query- to request) to another and there is no defined solution to handle possible conflicts.

If I think about the expected behavior, I would say that defaults of QueryParamFetcher should take precedence because it is the place where I define the query-parameter I am actually sending. This would also play nice with the term "force" in the ParamFetcher-config.

So imho there are two possible solutions:

  • Give precedence to QueryParamFetcher:
    • the QueryParam overwrite defaults of the route-definition / ParamConverter.
    • the defaults are defined in the QueryParam-Annotation. Possible defaults in the method-signature or route-definition are ignored if both set.
    • There should no exception to be thrown if both set defaults
    • this behavior should be documented
  • Define the actual behavior as expected and document it because we think the conflict can't be decided by the bundle

Either way, there should be a defined and documented way to resolve this (or not) :)

benbender avatar Apr 21 '13 12:04 benbender

  • +1 the QueryParam overwrite defaults of the route-definition / ParamConverter.

dewos avatar May 05 '13 19:05 dewos

Could anyone review my issue:

https://github.com/FriendsOfSymfony/FOSRestBundle/issues/774

Thanks in advance.

ghost avatar May 20 '14 15:05 ghost