|
17 | 17 | use ApiPlatform\Hydra\State\Util\SearchHelperTrait; |
18 | 18 | use ApiPlatform\JsonLd\Serializer\HydraPrefixTrait; |
19 | 19 | use ApiPlatform\Metadata\FilterInterface; |
20 | | -use ApiPlatform\Metadata\QueryParameterInterface; |
21 | 20 | use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface; |
22 | 21 | use ApiPlatform\Metadata\ResourceClassResolverInterface; |
23 | 22 | use ApiPlatform\State\Util\StateOptionsTrait; |
@@ -108,20 +107,9 @@ public function normalize(mixed $data, ?string $format = null, array $context = |
108 | 107 |
|
109 | 108 | $resourceClass = $this->getStateOptionsClass($operation, $resourceClass); |
110 | 109 |
|
111 | | - $hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); |
112 | | - ['mapping' => $mapping, 'keys' => $keys] = $this->getSearchMappingAndKeys($operation, $resourceClass, $currentFilters, $parameters, [$this, 'getFilter']); |
113 | | - |
114 | | - $hasQueryParameters = false; |
115 | | - if ($parameters) { |
116 | | - foreach ($parameters as $parameter) { |
117 | | - if ($parameter instanceof QueryParameterInterface) { |
118 | | - $hasQueryParameters = true; |
119 | | - break; |
120 | | - } |
121 | | - } |
122 | | - } |
123 | | - |
124 | | - if ($currentFilters || $keys || $hasQueryParameters) { |
| 110 | + if ($currentFilters || ($parameters && \count($parameters))) { |
| 111 | + $hydraPrefix = $this->getHydraPrefix($context + $this->defaultContext); |
| 112 | + ['mapping' => $mapping, 'keys' => $keys] = $this->getSearchMappingAndKeys($operation, $resourceClass, $currentFilters, $parameters, [$this, 'getFilter']); |
125 | 113 | $normalizedData[$hydraPrefix.'search'] = [ |
126 | 114 | '@type' => $hydraPrefix.'IriTemplate', |
127 | 115 | $hydraPrefix.'template' => \sprintf('%s{?%s}', $requestParts['path'], implode(',', $keys)), |
|
0 commit comments