[Bug]: problem with traversables
Opened this issue · 2 comments
Version
all
Description
Before this PR in property info, documenting a property like this:
/**
* @var \Doctrine\Common\Collections\Collection<SomeClass>
*/
public $someClasses
was ok-ish, because property-info was creating a Type such as:
Symfony\Component\PropertyInfo\Type^ {#23829
-builtinType: "object"
-nullable: false
-class: "Doctrine\Common\Collections\Collection"
-collection: true
-collectionKeyType: array:0 []
-collectionValueType: array:1 [
0 => Symfony\Component\PropertyInfo\Type^ {#23825
-builtinType: "object"
-nullable: false
-class: "App\Domain\SomeClass"
-collection: false
-collectionKeyType: []
-collectionValueType: []
}
]
}
and then, ArrayPropertyDescriber
was used because, the collection type does not have any collectionKeyType
.
But now, for the same phpdoc annotation, the collection gets created with two collectionKeyType
:
-collectionKeyType: array:2 [
0 => Symfony\Component\PropertyInfo\Type^ {#23827
-builtinType: "string"
// ...
}
1 => Symfony\Component\PropertyInfo\Type^ {#23830
-builtinType: "int"
// ...
}
]
and then ArrayPropertyDescriber
is not used anymore. And it result in the following error:
Schema of type "\Doctrine\Common\Collections\Collection" can't be generated, no describer supports it
I'm not really sure about the solution... maybe create a new TraversablePropertyDescriber
would be enough?
JSON OpenApi
No response
Additional context
No response
I think this is mainly an issue with the way symfony/property-info
handles unions. I think you should be able to fix this by specifying the key type of your collection:
/**
* @var \Doctrine\Common\Collections\Collection<int, SomeClass>
*/
public $someClasses
Adding support for the newly added symfony/type-info
component might offer a solution. https://symfony.com/doc/current/components/type_info.html