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

Merged
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
23 changes: 21 additions & 2 deletions src/State/Provider/DeserializeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,13 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
if (!$exception instanceof NotNormalizableValueException) {
continue;
}
$message = (new Type($exception->getExpectedTypes() ?? []))->message;
$expectedTypes = $this->normalizeExpectedTypes($exception->getExpectedTypes());
$message = (new Type($expectedTypes))->message;
$parameters = [];
if ($exception->canUseMessageForUser()) {
$parameters['hint'] = $exception->getMessage();
}
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $exception->getExpectedTypes() ?? [])], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, (string) Type::INVALID_TYPE_ERROR));
$violations->add(new ConstraintViolation($this->translator->trans($message, ['{{ type }}' => implode('|', $expectedTypes)], 'validators'), $message, $parameters, null, $exception->getPath(), null, null, (string) Type::INVALID_TYPE_ERROR));
}
if (0 !== \count($violations)) {
throw new ValidationException($violations);
Expand All @@ -114,4 +115,22 @@ public function provide(Operation $operation, array $uriVariables = [], array $c

return $data;
}

private function normalizeExpectedTypes(?array $expectedTypes = null): array
{
$normalizedTypes = [];

foreach ($expectedTypes ?? [] as $expectedType) {
$normalizedType = $expectedType;

if (class_exists($expectedType) || interface_exists($expectedType)) {
$classReflection = new \ReflectionClass($expectedType);
$normalizedType = $classReflection->getShortName();
}

$normalizedTypes[] = $normalizedType;
}

return $normalizedTypes;
}
}
Loading