@@ -100,12 +100,13 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
100100 if (!$ exception instanceof NotNormalizableValueException) {
101101 continue ;
102102 }
103- $ message = (new Type ($ exception ->getExpectedTypes () ?? []))->message ;
103+ $ expectedTypes = $ this ->normalizeExpectedTypes ($ exception ->getExpectedTypes ());
104+ $ message = (new Type ($ expectedTypes ))->message ;
104105 $ parameters = [];
105106 if ($ exception ->canUseMessageForUser ()) {
106107 $ parameters ['hint ' ] = $ exception ->getMessage ();
107108 }
108- $ 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 ));
109+ $ violations ->add (new ConstraintViolation ($ this ->translator ->trans ($ message , ['{{ type }} ' => implode ('| ' , $ expectedTypes )], 'validators ' ), $ message , $ parameters , null , $ exception ->getPath (), null , null , (string ) Type::INVALID_TYPE_ERROR ));
109110 }
110111 if (0 !== \count ($ violations )) {
111112 throw new ValidationException ($ violations );
@@ -114,4 +115,22 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
114115
115116 return $ data ;
116117 }
118+
119+ private function normalizeExpectedTypes (?array $ expectedTypes = null ): array
120+ {
121+ $ normalizedTypes = [];
122+
123+ foreach ($ expectedTypes ?? [] as $ expectedType ) {
124+ $ normalizedType = $ expectedType ;
125+
126+ if (class_exists ($ expectedType ) || interface_exists ($ expectedType )) {
127+ $ classReflection = new \ReflectionClass ($ expectedType );
128+ $ normalizedType = $ classReflection ->getShortName ();
129+ }
130+
131+ $ normalizedTypes [] = $ normalizedType ;
132+ }
133+
134+ return $ normalizedTypes ;
135+ }
117136}
0 commit comments