Skip to content

Commit

Permalink
fix(symfony): allow schema restriction for collection like property f…
Browse files Browse the repository at this point in the history
…rom choice constraint (#6520)
  • Loading branch information
c1tru55 authored Aug 29, 2024
1 parent 3b42c9f commit 0a461d7
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ public function create(Constraint $constraint, ApiProperty $propertyMetadata): a
*/
public function supports(Constraint $constraint, ApiProperty $propertyMetadata): bool
{
$types = array_map(fn (Type $type) => $type->getBuiltinType(), $propertyMetadata->getBuiltinTypes() ?? []);
$types = array_map(static fn (Type $type) => $type->getBuiltinType(), $propertyMetadata->getBuiltinTypes() ?? []);
if ($propertyMetadata->getExtraProperties()['nested_schema'] ?? false) {
$types = [Type::BUILTIN_TYPE_STRING];
}

if (
null !== ($builtinType = $propertyMetadata->getBuiltinTypes()[0] ?? null)
&& $builtinType->isCollection()
&& \count($builtinType->getCollectionValueTypes())
) {
$types = array_unique(array_merge($types, array_map(static fn (Type $type) => $type->getBuiltinType(), $builtinType->getCollectionValueTypes())));
}

return $constraint instanceof Choice && \count($types) && array_intersect($types, [Type::BUILTIN_TYPE_STRING, Type::BUILTIN_TYPE_INT, Type::BUILTIN_TYPE_FLOAT]);
}
}

0 comments on commit 0a461d7

Please sign in to comment.