1919use Symfony \Component \Serializer \Exception \NotNormalizableValueException ;
2020use Symfony \Component \Serializer \Exception \PartialDenormalizationException ;
2121use Symfony \Component \Validator \Constraint ;
22+ use Symfony \Component \Validator \Constraints \GroupSequence ;
2223use Symfony \Component \Validator \Constraints \NotBlank ;
2324use Symfony \Component \Validator \Constraints \NotNull ;
2425use Symfony \Component \Validator \Constraints \Type ;
@@ -126,7 +127,7 @@ private function buildViolation(NotNormalizableValueException $exception, Operat
126127 return null ;
127128 }
128129
129- $ validationGroups = ( $ operation ->getValidationContext () ?? [])['groups ' ] ?? null ;
130+ $ validationGroups = $ this -> normalizeValidationGroups (( $ operation ->getValidationContext () ?? [])['groups ' ] ?? null ) ;
130131 $ constraints = $ this ->collectConstraints ($ classMetadata , $ path , $ validationGroups );
131132 if (!$ constraints ) {
132133 return null ;
@@ -151,6 +152,53 @@ private function buildViolation(NotNormalizableValueException $exception, Operat
151152 return $ this ->emitViolation ($ exception , new Type ([]), (string ) Type::INVALID_TYPE_ERROR );
152153 }
153154
155+ /**
156+ * Normalizes the operation's validation groups into a flat list of group names.
157+ *
158+ * The `groups` entry of the validation context may be a plain list, a {@see GroupSequence},
159+ * or a list mixing nested arrays and GroupSequence instances. A callable (resolved at
160+ * validation time against the object) cannot be evaluated here and is treated as absent.
161+ *
162+ * @return array<string>|null
163+ */
164+ private function normalizeValidationGroups (mixed $ validationGroups ): ?array
165+ {
166+ if (null === $ validationGroups ) {
167+ return null ;
168+ }
169+
170+ if ($ validationGroups instanceof GroupSequence) {
171+ return $ this ->flattenValidationGroups ($ validationGroups ->groups );
172+ }
173+
174+ if (!\is_array ($ validationGroups ) || \is_callable ($ validationGroups )) {
175+ return null ;
176+ }
177+
178+ return $ this ->flattenValidationGroups ($ validationGroups );
179+ }
180+
181+ /**
182+ * @param array<string|array<mixed>|GroupSequence> $groups
183+ *
184+ * @return array<string>
185+ */
186+ private function flattenValidationGroups (array $ groups ): array
187+ {
188+ $ flattenGroups = [];
189+ foreach ($ groups as $ group ) {
190+ if (\is_array ($ group )) {
191+ $ flattenGroups [] = $ this ->flattenValidationGroups ($ group );
192+ } elseif ($ group instanceof GroupSequence) {
193+ $ flattenGroups [] = $ this ->flattenValidationGroups ($ group ->groups );
194+ } else {
195+ $ flattenGroups [] = [$ group ];
196+ }
197+ }
198+
199+ return array_merge ([], ...$ flattenGroups );
200+ }
201+
154202 /**
155203 * @param array<string>|null $validationGroups
156204 *
0 commit comments