Strip unprovided parameters from returned data ->all()
FOSRestBundle version: 2.5.0
Is there a way to prevent that all QueryParam(s), which are not specifically provided, to be returned as value "" or null?
Lets say we have the following code snippet
/**
* @QueryParam(name="valueX", description="Value X", nullable=true)
* @QueryParam(name="valueY", description="Value Y")
* @QueryParam(name="valueZ", description="Value Z")
*
* @param ParamFetcher $params
*
* @return View
*/
public function cgetAction(ParamFetcher $params): View
{
dump($params->all());
return ...;
}
Which the provided query string
/endpoint.json?valueY=any_value&valueZ=any_other_value
Returns
array:3 [
"valueX" => null,
"valueY" => "any_value",
"valueZ" => "any_other_value"
]
Is there a possibility to simply strip the valueX key value, since we have not provided it in the initial query anyways?
array:2 [
"valueY" => "any_value",
"valueZ" => "any_other_value"
]
Former versions of the rest bundle (~1.*) would indeed strip the empty key values. After upgrading to 2.5 some issues are faced due to using isset() in the codebase to check if a parameter was provided (whether that was a good idea or not...)
@xabbuh will you realize this feature? If you have no time I can try to do that
@gam6itko You said former versions of the bundle did not expose this behaviour. Did you manage to find out which commit exactly introduced the change in behaviour?
@xabbuh I reckon you meant to tag me; I will try to track down which commit caused this behavior in the next few days.
@imbue Oh I didn't realise that you didn't write the last comment. 🙈 Thank you!