Skip to content

fix(state): do not expose FQCN in DeserializeProvider on PartialDenormalizationException #7158

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

Conversation

alexndlm
Copy link
Contributor

Q A
Branch? 4.1
Tickets Closes #7149
License MIT
Doc PR

Also relates to https://github.com/api-platform/core/pull/6761/files

@@ -36,6 +37,7 @@ public function __construct(
private readonly ?ProviderInterface $decorated,
private readonly SerializerInterface $serializer,
private readonly SerializerContextBuilderInterface $serializerContextBuilder,
private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
Copy link
Member

Choose a reason for hiding this comment

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

It bothers me that we need to inject this but I guess there's no other solution unless we only use reflection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if we want to use a short name, we need this service.

I would leave only a reflection, for simplicity. However, I can't assess how well it meets the general concept of the API Platform.


if (class_exists($expectedType) || interface_exists($expectedType)) {
try {
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName();
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()?->getShortName();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have checked \ApiPlatform\Metadata\Resource\ResourceMetadataCollection::getOperation, it always returns Operation.

if (class_exists($expectedType) || interface_exists($expectedType)) {
try {
$normalizedType = $this->resourceMetadataCollectionFactory->create($expectedType)->getOperation()->getShortName();
} catch (\Throwable) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} catch (\Throwable) {
} catch (OperationNotFoundException) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

if (null === $normalizedType) {
$classReflection = new \ReflectionClass($expectedType);
$normalizedType = $classReflection->getShortName();
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this is quite sufficient actually (I thought we could re-use the current operation in the normalizers/denormalizers) but indeed in that case the type may be another one then the current operation's one...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should fetch the operation exactly for class in $expectedType.

@alexndlm alexndlm requested a review from soyuka May 20, 2025 07:44
@soyuka
Copy link
Member

soyuka commented May 22, 2025

I reverted the addition of the metadata factory reflection is enough imo.
For the future, note that introducing a new parameter in a constructor it needs to be nullable and we need to cover a bc layer (can't change the order of arguments). Anyways this is quite sufficient like this, many thanks!

@soyuka soyuka force-pushed the feature/state-do-not-expose-FQCN-in-DeserializeProvider branch from 86c5485 to 498d309 Compare May 22, 2025 08:41
@soyuka soyuka merged commit 9c0dbb6 into api-platform:4.1 May 22, 2025
93 of 94 checks passed
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

Successfully merging this pull request may close these issues.

2 participants