Skip to content

Do not apply filters is filters option is already set on an operation #5665

@vincentchalamon

Description

@vincentchalamon

API Platform version(s) affected: 3.x

Description
Considering the following resource:

#[ApiResource( types: ['https://schema.org/Review'], operations: [ new GetCollection(), new Get(), ], routePrefix: '/admin', security: 'is_granted("ROLE_ADMIN")' )] #[ApiResource( uriTemplate: '/books/{bookId}/reviews{._format}', types: ['https://schema.org/Review'], operations: [ new GetCollection(filters: [], itemUriTemplate: '/books/{bookId}/reviews/{id}{._format}'), new NotExposed( uriTemplate: '/books/{bookId}/reviews/{id}{._format}', uriVariables: [ 'bookId' => new Link(toProperty: 'book', fromClass: Book::class), 'id' => new Link(fromClass: Review::class), ], ), ], uriVariables: [ 'bookId' => new Link(toProperty: 'book', fromClass: Book::class), ], )] class Review { #[ApiFilter(NumericFilter::class)] public ?int $rating = null;

The filter on rating must be applied only on the first ApiResource (/admin/reviews), not the second one. To do so, I set the filters: [] option to disable all filters. But the FiltersResourceMetadataCollectionFactory erases this configuration.

Possible Solution
Do not set filters on FiltersResourceMetadataCollectionFactory is filters is not null.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions