Skip to content

Commit 65ac0d2

Browse files
committed
fix(symfony): property info with doctrine collections
1 parent 06f54d4 commit 65ac0d2

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
2020
use ApiPlatform\Metadata\ResourceClassResolverInterface;
2121
use ApiPlatform\Metadata\Util\ResourceClassInfoTrait;
22+
use Doctrine\Common\Collections\ArrayCollection;
2223
use Ramsey\Uuid\UuidInterface;
2324
use Symfony\Component\PropertyInfo\Type;
2425
use Symfony\Component\Uid\Ulid;
@@ -110,6 +111,11 @@ public function create(string $resourceClass, string $property, array $options =
110111

111112
$valueSchema = [];
112113
foreach ($types as $type) {
114+
// Temp fix for https://github.com/symfony/symfony/pull/52699
115+
if (ArrayCollection::class === $type->getClassName()) {
116+
$type = new Type($type->getBuiltinType(), $type->isNullable(), $type->getClassName(), true, $type->getCollectionKeyTypes(), $type->getCollectionValueTypes());
117+
}
118+
113119
if ($isCollection = $type->isCollection()) {
114120
$keyType = $type->getCollectionKeyTypes()[0] ?? null;
115121
$valueType = $type->getCollectionValueTypes()[0] ?? null;

src/Metadata/Property/Factory/PropertyInfoPropertyMetadataFactory.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
use ApiPlatform\Metadata\ApiProperty;
1717
use ApiPlatform\Metadata\Exception\PropertyNotFoundException;
18+
use Doctrine\Common\Collections\ArrayCollection;
1819
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
20+
use Symfony\Component\PropertyInfo\Type;
1921

2022
/**
2123
* PropertyInfo metadata loader decorator.
@@ -44,7 +46,16 @@ public function create(string $resourceClass, string $property, array $options =
4446
}
4547

4648
if (!$propertyMetadata->getBuiltinTypes()) {
47-
$propertyMetadata = $propertyMetadata->withBuiltinTypes($this->propertyInfo->getTypes($resourceClass, $property, $options) ?? []);
49+
$types = $this->propertyInfo->getTypes($resourceClass, $property, $options) ?? [];
50+
51+
foreach ($types as $i => $type) {
52+
// Temp fix for https://github.com/symfony/symfony/pull/52699
53+
if (ArrayCollection::class === $type->getClassName()) {
54+
$types[$i] = new Type($type->getBuiltinType(), $type->isNullable(), $type->getClassName(), true, $type->getCollectionKeyTypes(), $type->getCollectionValueTypes());
55+
}
56+
}
57+
58+
$propertyMetadata = $propertyMetadata->withBuiltinTypes($types);
4859
}
4960

5061
if (null === $propertyMetadata->getDescription() && null !== $description = $this->propertyInfo->getShortDescription($resourceClass, $property, $options)) {

tests/Fixtures/TestBundle/ApiResource/Issue5501/BrokenDocs.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BrokenDocs
3030
public ?int $id = null;
3131

3232
/**
33-
* @var ?Related[]
33+
* @var ?ArrayCollection<Related>
3434
*/
3535
#[Groups(['location:write', 'location:read_collection'])]
3636
public ?ArrayCollection $locations;

0 commit comments

Comments
 (0)