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

ElasticSearch ItemNormalizer has incorrect return type on normalize #6492

Closed
Koenstell opened this issue Jul 24, 2024 · 0 comments
Closed

ElasticSearch ItemNormalizer has incorrect return type on normalize #6492

Koenstell opened this issue Jul 24, 2024 · 0 comments

Comments

@Koenstell
Copy link
Contributor

Koenstell commented Jul 24, 2024

API Platform version(s) affected: 3.3.11

Description
When using API Platform combined with Elasticsearch, it will prioritize the ItemNormalizer to allow documents from Elastic to be normalized as well. However, the method signature of this class does not comply with its parents, which means that if somewhere else you use a normalizer through the NormalizerInterface DI, you could end up with this error:

ApiPlatform\Elasticsearch\Serializer\ItemNormalizer::normalize(): Return value must be of type array, string returned

How to reproduce

  • Use API Platform with Elasticsearch enabled
  • Inject the normalizer in a random controller using DI: private readonly NormalizerInterface $normalizer
  • Try to normalize an entity manually: $this->normalizer->normalize($entity, null, ['groups' => ['example']]);

Possible Solution
Change the method signature of the ElasticSearch ItemNormalizer. Located at ApiPlatform\Elasticsearch\Serializer\ItemNormalizer.

Like so:
BEFORE

public function normalize(mixed $object, ?string $format = null, array $context = []): array
{
    return $this->decorated->normalize($object, $format, $context);
}

AFTER:

public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
{
    return $this->decorated->normalize($object, $format, $context);
}
@Koenstell Koenstell changed the title ElasticSearch ItemNormalizer has incorrect method signature on normalize ElasticSearch ItemNormalizer has incorrect return type on normalize Jul 24, 2024
@soyuka soyuka closed this as completed Aug 8, 2024
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

No branches or pull requests

2 participants