Fosrestbundle: QueryParam 'incompatibles' attribute does not work as expected

Created on 17 Nov 2016  路  1Comment  路  Source: FriendsOfSymfony/FOSRestBundle

According to the official symfony docs, using the 'incompatibles' attribute it is possible to prevent clients requesting n parameters simultaneously:

@RequestParam(name="search", requirements="[a-z]+", description="search")
* @RequestParam(name="byauthor", requirements="[a-z]+", description="by author", incompatibles={"search"})
* Imagine you have an api for a blog with to get Articles with two ways of filtering
* 1 by filtering the text
* 2 by filtering the author
* and you don't have yet implemented the possibility to filter by both at the same time.
* In order to prevent clients from doing a request with both (which will produce not the expected
* resut and is likely to be considered as a bug) you can precise the parameters can't be present
* at the same time by doing

This is my set up:

/**
   * @Annotations\Get(path="/test", options={"expose" = true})
   * @Annotations\QueryParam(
   *    name="search",
   *    requirements="[a-z]+",
   *    description="search"
   * )
   * @Annotations\QueryParam(
   *    name="byauthor",
   *    requirements="[a-z]+",
   *    description="by author",
   *    incompatibles={"search"}
   * )
   */

If I call the following url:

/test?search=text&byauthor=author

as expected, I receive a 400 Bad Request with the following error message:

'byauthor' param is incompatible with search param.

But if i call the following url:

/test?search=text

I receive a 400 Bad Request with message:

'byauthor' param is incompatible with search param.

Most helpful comment

@GuilhemN i think this issue can be closed

>All comments

@GuilhemN i think this issue can be closed

Was this page helpful?
0 / 5 - 0 ratings