docs(filters): document enhanced QueryParameter syntax on old filters#2227
Conversation
1409cd7 to
4340fda
Compare
|
Thank you for improving the documentation. Please allow me to share my insights. In v4.2.3, when setting filters using - parameters: [
- 'search[:property]' => new QueryParameter(/* ... */)
+ parameters: [
+ new QueryParameter(key: 'search[:property]', /* ... */)Also, directly passing a filter instance to the For example, I have observed the following issues in my environment.
new QueryParameter(key: 'exists[content]', filter: new ExistsFilter(), property: 'content'),
new QueryParameter(key: 'exists[comments]', filter: new ExistsFilter(), property: 'comments'),
new QueryParameter(key: 'order[id]', filter: new OrderFilter(), property: 'id'),
new QueryParameter(key: 'order[date]', filter: new OrderFilter(), property: 'date'), |
aegypius
left a comment
There was a problem hiding this comment.
polish: I made a bunch of suggestions regarding spelling.
About the other issues we refactored the code for the |
… usage - Updated documentation to promote the `QueryParameter` attribute over `ApiFilter`, as the latter is deprecated and scheduled for removal in API Platform 5.0. - Added examples for Date, Boolean, Numeric, Range, Exists, and Order filters using the `QueryParameter` approach. Included notes on configuring custom strategies, handling null values, and enabling filters for nested properties.
Co-authored-by: Nicolas LAURENT <aegypius@users.noreply.github.com>
34bec11 to
557c93e
Compare
|
Many thanks for the work on this! I'll fix linting issues in another PR! |
Thank you for the detailed explanation. I finally understand the conditions for reproduction. I declare parameters as follows in the #[ORM\Entity(repositoryClass: ArticleRepository::class)]
class Article
{
// ...
public static function apiResource(): array
{
return [
new GetCollection(
parameters: [
new QueryParameter(filter: new DateFilter(), key: ':property', properties: ['date']),
],
),
];
}
}If we declare it as follows using class attributes, the output will be correct. #[GetCollection(
parameters: [
new QueryParameter(filter: new DateFilter(), key: ':property', properties: ['date']),
],
)]
#[ORM\Entity(repositoryClass: ArticleRepository::class)]
class Article
{
// ...
}Incidentally, even if we declare it as follows using a PHP resource file, OpenAPI/Hydra still does not output correctly. <?php
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operations;
use ApiPlatform\Metadata\QueryParameter;
use App\Entity\Article;
return (new ApiResource())
->withClass(Article::class)
->withOperations(new Operations([
new GetCollection(
parameters: [
new QueryParameter(filter: new DateFilter(), key: ':property', properties: ['date']),
],
),
]))
;Do you know what the cause is? |
|
@soyuka At api-platform/core#7654 and api-platform/core#7655, I have exhaustively summarized the filter-related bugs I'm aware of in the Issues. Apologies for the trouble, but please check them. |
Completes #2203
And here to avoid these issues:
QueryParameter, it is not possible to set multiple filters for the same property core#7493:propertykey cannot be used inSearchFilter(Symfony only) core#7495Main changes:
QueryParameterapproach. Included notes on configuring custom strategies, handling null values, and enabling filters for nested properties.QueryParameterattribute overApiFilter, as the latter is deprecated and scheduled for removal in API Platform 5.0.