Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Elasticsearch/Filter/AbstractSearchFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function getDescription(string $resourceClass): array
'property' => $property,
'type' => $hasAssociation ? 'string' : $this->getPhpType($type),
'required' => false,
'is_collection' => str_ends_with((string) $filterParameterName, '[]'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we check the $type (or even $types) instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only be applied for "{$property}[]" and the $type property does not have this information. I use the same implementation as is done for doctrine https://github.com/api-platform/core/blob/main/src/Doctrine/Common/Filter/SearchFilterTrait.php#L79

];
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/Elasticsearch/Filter/MatchFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,49 @@ public function testGetDescription(): void
'property' => 'id',
'type' => 'int',
'required' => false,
'is_collection' => false,
],
'id[]' => [
'property' => 'id',
'type' => 'int',
'required' => false,
'is_collection' => true,
],
'name' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'is_collection' => false,
],
'name[]' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'is_collection' => true,
],
'date' => [
'property' => 'date',
'type' => \DateTimeInterface::class,
'required' => false,
'is_collection' => false,
],
'date[]' => [
'property' => 'date',
'type' => \DateTimeInterface::class,
'required' => false,
'is_collection' => true,
],
'weird' => [
'property' => 'weird',
'type' => 'string',
'required' => false,
'is_collection' => false,
],
'weird[]' => [
'property' => 'weird',
'type' => 'string',
'required' => false,
'is_collection' => true,
],
],
$matchFilter->getDescription(Foo::class)
Expand Down
8 changes: 8 additions & 0 deletions tests/Elasticsearch/Filter/TermFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,41 +176,49 @@ public function testGetDescription(): void
'property' => 'id',
'type' => 'int',
'required' => false,
'is_collection' => false,
],
'id[]' => [
'property' => 'id',
'type' => 'int',
'required' => false,
'is_collection' => true,
],
'name' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'is_collection' => false,
],
'name[]' => [
'property' => 'name',
'type' => 'string',
'required' => false,
'is_collection' => true,
],
'date' => [
'property' => 'date',
'type' => \DateTimeInterface::class,
'required' => false,
'is_collection' => false,
],
'date[]' => [
'property' => 'date',
'type' => \DateTimeInterface::class,
'required' => false,
'is_collection' => true,
],
'weird' => [
'property' => 'weird',
'type' => 'string',
'required' => false,
'is_collection' => false,
],
'weird[]' => [
'property' => 'weird',
'type' => 'string',
'required' => false,
'is_collection' => true,
],
],
$termFilter->getDescription(Foo::class)
Expand Down