Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(doctrine): allow for comma-separated values in numeric-filter #6720

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

frankdekker
Copy link

Q A
Branch? main
Tickets -
License MIT
Doc PR api-platform/docs#2037

Currently the NumericFilter allows for searching for numeric-string or numeric-string[]:

/api/entity?numericValue=5
/api/entity?numericValue[]=5&numericValue[]=6

This PR adds the support for comma-separated numeric-values:

/api/entity?numericValue=5,6

Which allows for much shorter urls when searching on multiple numeric values and if I understand the specification correctly this is a valid format. A snipper from the documentation:

Query parameters can be primitive values, arrays and objects. OpenAPI 3.0 provides several ways to serialize objects and arrays in the query string.

Arrays can be serialized as:

form – /products?color=blue,green,red or /products?color=blue&color=green, depending on the explode keyword

https://swagger.io/docs/specification/v3_0/describing-parameters/#query-parameters

@frankdekker
Copy link
Author

I'm a bit lost how to test the NumericFilter. Looking at src/Doctrine/Orm, running composer install in this directory and then starting the test will use the api-platform/core classes from vendor instead of using src/Doctrine/Orm/Filter/NumericFilter.php

If I run the test with phpunit from the root of the project, the test crashes as the Doctrine driver can't be found.

I could use some tips how to solve this.

@frankdekker frankdekker marked this pull request as ready for review October 15, 2024 08:04
@soyuka
Copy link
Member

soyuka commented Oct 17, 2024

I'm really not sure we want to add this to our codebase as all our filters work by having this syntax:

/api/entity?numericValue[]=5&numericValue[]=6

With the QueryParameter we tried to improve the tools users can use to re-use filters but in their own way, it should be fairly easy to add (and document) this in your own codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants