core
core copied to clipboard
`ApiFilter` does not respect `SerializerName`
API Platform version(s) affected: v3.1.18
Description
The following will not work:
#[ApiResource(
operations: [
new GetCollection(),
],
)]
#[ApiFilter(DateFilter::class, properties: [
'date',
])]
class Foo
{
#[SerializedName('date')]
public \DateTimeInterface $reallyBadlyNamedDateForLegacyReasons;
}
beacuse the filters do not consider the SerializerName
of the attribute we want to filter on
How to reproduce
Possible Solution
- Some code here which takes into account the
SerializedName
here? https://github.com/api-platform/core/blob/main/src/Doctrine/Orm/Filter/AbstractFilter.php#L89
I really need to tackle this with #2400 as once we reach doctrine filters we should already know the correct property right?
@soyuka having thought about this, i think this is tricky to solve. what if we had a Resource like this.
#[ApiResource(
operations: [
new GetCollection(),
],
)]
#[ApiFilter(DateFilter::class, properties: [
'date',
])]
class Foo
{
#[SerializedName('date')]
public \DateTimeInterface $reallyBadlyNamedDateForLegacyReasons;
public \DateTimeInterface $date;
}
what then?
i think there will be many other edge cases which we can't envisage, like groups and SerializedPath.
and this won't work with stateOptions: new Options(entityClass: ...::class)
where your entity is not the serialized class
Instead, i don't think we should support serializer attributes at all, and instead https://github.com/api-platform/core/issues/5981 is a better, far more flexible solution.
Hello!
I think it's needed to handle also the possibility to use this name for the validation constrains and also when using attributes to specify the attributes to get.