core icon indicating copy to clipboard operation
core copied to clipboard

`ExistsFilter` and `OrderFilter` output incorrect parameter names to Hydra's `search` property (Symfony only)

Open ttskch opened this issue 2 months ago • 0 comments

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.

ExistsFilter and OrderFilter output incorrect parameter names to Hydra's search property (Symfony only)

#[QueryParameter(key: 'exists[title]', filter: 'serviceId.for.exists_filter')]
#[QueryParameter(key: 'order[id]', filter: 'serviceId.for.order_filter')]

For example, applying ExistsFilter and OrderFilter using the code above results in incorrect parameter names being output in Hydra's search property, such as exists[exists[title]] and order[order[id]], which are double-nested. This problem only occurs with Symfony and does not occur with Laravel's OrderFilter.

{
  "@context": "/api/contexts/Book",
  "@id": "/api/books",
  "@type": "Collection",
  "totalItems": 10,
  "member": [
    // ...
  ],
  "search": {
    "@type": "IriTemplate",
    "template": "/api/books{?exists[exists[title]],order[order[id]]}",
    "variableRepresentation": "BasicRepresentation",
    "mapping": [
      {
        "@type": "IriTemplateMapping",
        "variable": "exists[exists[title]]",
        "property": "title",
        "required": false
      },
      {
        "@type": "IriTemplateMapping",
        "variable": "order[order[id]]",
        "property": "id",
        "required": false
      }
    ]
  }
}

ttskch avatar Oct 30 '25 07:10 ttskch