Skip to content

Commit 0a461d7

Browse files
authoredAug 29, 2024··
fix(symfony): allow schema restriction for collection like property from choice constraint (#6520)
1 parent 3b42c9f commit 0a461d7

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎src/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaChoiceRestriction.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,19 @@ public function create(Constraint $constraint, ApiProperty $propertyMetadata): a
7878
*/
7979
public function supports(Constraint $constraint, ApiProperty $propertyMetadata): bool
8080
{
81-
$types = array_map(fn (Type $type) => $type->getBuiltinType(), $propertyMetadata->getBuiltinTypes() ?? []);
81+
$types = array_map(static fn (Type $type) => $type->getBuiltinType(), $propertyMetadata->getBuiltinTypes() ?? []);
8282
if ($propertyMetadata->getExtraProperties()['nested_schema'] ?? false) {
8383
$types = [Type::BUILTIN_TYPE_STRING];
8484
}
8585

86+
if (
87+
null !== ($builtinType = $propertyMetadata->getBuiltinTypes()[0] ?? null)
88+
&& $builtinType->isCollection()
89+
&& \count($builtinType->getCollectionValueTypes())
90+
) {
91+
$types = array_unique(array_merge($types, array_map(static fn (Type $type) => $type->getBuiltinType(), $builtinType->getCollectionValueTypes())));
92+
}
93+
8694
return $constraint instanceof Choice && \count($types) && array_intersect($types, [Type::BUILTIN_TYPE_STRING, Type::BUILTIN_TYPE_INT, Type::BUILTIN_TYPE_FLOAT]);
8795
}
8896
}

0 commit comments

Comments
 (0)
Please sign in to comment.