14
14
namespace ApiPlatform \Symfony \Validator \State ;
15
15
16
16
use ApiPlatform \Metadata \Operation ;
17
+ use ApiPlatform \Metadata \Parameter ;
17
18
use ApiPlatform \State \ParameterNotFound ;
18
19
use ApiPlatform \State \ProviderInterface ;
19
20
use ApiPlatform \State \Util \ParameterParserTrait ;
@@ -68,9 +69,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
68
69
$ violation ->getMessageTemplate (),
69
70
$ violation ->getParameters (),
70
71
$ violation ->getRoot (),
71
- $ parameter ->getProperty () ?? (
72
- str_contains ($ key , ':property ' ) ? str_replace ('[:property] ' , $ violation ->getPropertyPath (), $ key ) : $ key .$ violation ->getPropertyPath ()
73
- ),
72
+ $ this ->getProperty ($ parameter , $ violation ),
74
73
$ violation ->getInvalidValue (),
75
74
$ violation ->getPlural (),
76
75
$ violation ->getCode (),
@@ -86,4 +85,24 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
86
85
87
86
return $ this ->decorated ->provide ($ operation , $ uriVariables , $ context );
88
87
}
88
+
89
+ // There's a `property` inside Parameter but it's used for hydra:search only as here we want the parameter name instead
90
+ private function getProperty (Parameter $ parameter , ConstraintViolation $ violation )
91
+ {
92
+ $ key = $ parameter ->getKey ();
93
+
94
+ if (str_contains ($ key , '[:property] ' )) {
95
+ return str_replace ('[:property] ' , $ violation ->getPropertyPath (), $ key );
96
+ }
97
+
98
+ if (str_contains ($ key , ':property ' )) {
99
+ return str_replace (':property ' , $ violation ->getPropertyPath (), $ key );
100
+ }
101
+
102
+ if ($ p = $ violation ->getPropertyPath ()) {
103
+ return $ p ;
104
+ }
105
+
106
+ return $ key ;
107
+ }
89
108
}
0 commit comments