-
-
Notifications
You must be signed in to change notification settings - Fork 936
Description
API Platform version(s) affected: 4.2.2
Description
As the document warns, ApiFilter is currently deprecated and using QueryParameter is recommended.
However, there are several bugs when applying filters using QueryParameter.
- With
QueryParameter, it is not possible to set multiple filters for the same property ExistsFilterandOrderFilteroutput incorrect parameter names to Hydra'ssearchproperty (Symfony only):propertykey cannot be used inSearchFilter(Symfony only)
With QueryParameter, it is not possible to set multiple filters for the same property
For example, if we want to apply both NumericFilter and RangeFilter to the id property, we can achieve this with ApiFilter as follows:
#[ApiFilter(NumericFilter::class, properties: ['id'])]
#[ApiFilter(RangeFilter::class, properties: ['id'])]This will output the following parameters in OpenAPI, and these parameters will actually function correctly.
On the other hand, when using QueryParameter, we need to write it like this: (The key must be the same as the actual property name.)
#[QueryParameter(key: 'id', filter: 'serviceId.for.numeric_filter')]
#[QueryParameter(key: 'id', filter: 'serviceId.for.range_filter')]However, if we define multiple QueryParameters with the same key like this, the later definition overwrites the earlier one, so in this case, the NumericFilter will not work. The OpenAPI output will be as follows:
Note
Although writing it like this should be equivalent, currently there is a bug (#7492) where duplicate keys are only allowed when using the
parametersargument, so in this case, theNumericFilterhappens to work.#[ApiResource( parameters: [ new QueryParameter(key: 'id', filter: 'serviceId.for.numeric_filter'), new QueryParameter(key: 'id', filter: 'serviceId.for.range_filter'), ], )]However, this is not the intended behavior.

