php - How can I change the query format for arrays in API Platform?

I use last version of API Platform, and I was wondering if I could change the way to handle arrays in query string.

Default behavior relies on PHP way to handle arrays :

/customers?cars[]=audi&cars[]=mercedes&cars[]=bmw

According to Swagger documentation : https://swagger.io/docs/specification/serialization/, it can handle different ways :

/users?id=3,4,5
/users?id=3|4|5

Can I use this format using API Platform? I didn't find anything in the options, I suppose I can "trick" using Events (DeserializeListener maybe).

Answer

Solution:

This input format seems supported by Swagger: the style name of the parameter is deepObject.

There are many ways to support multiple inputs in query because the query is in fact a simple string containing var=value, therefore you can imagine whatever you want since var may be duplicated. PHP use the array-style (or deepObject) approach by default, and this is fine.

API Platform as support for this kind of "multiple filter" query by default: https://api-platform.com/docs/core/filters/#search-filter

If you want to use the following approach: /users?id=3|4|5, you can define a custom filter with ease and use the request directly to explode the id parameter and complete your query internally.

Source