mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Fix Symfony\Component\PropertyInfo\Type::getCollectionValueType() deprecation notice for symfony >=5.3
This commit is contained in:
parent
6ebb9cc9b4
commit
0667881cdb
@ -124,8 +124,8 @@ final class ModelRegistry
|
|||||||
|
|
||||||
private function getTypeShortName(Type $type): string
|
private function getTypeShortName(Type $type): string
|
||||||
{
|
{
|
||||||
if (null !== $type->getCollectionValueType()) {
|
if (null !== $collectionType = $this->getCollectionValueType($type)) {
|
||||||
return $this->getTypeShortName($type->getCollectionValueType()).'[]';
|
return $this->getTypeShortName($collectionType).'[]';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
||||||
@ -142,8 +142,8 @@ final class ModelRegistry
|
|||||||
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
||||||
return $type->getClassName();
|
return $type->getClassName();
|
||||||
} elseif ($type->isCollection()) {
|
} elseif ($type->isCollection()) {
|
||||||
if (null !== $type->getCollectionValueType()) {
|
if (null !== $collectionType = $this->getCollectionValueType($type)) {
|
||||||
return $this->typeToString($type->getCollectionValueType()).'[]';
|
return $this->typeToString($collectionType).'[]';
|
||||||
} else {
|
} else {
|
||||||
return 'mixed[]';
|
return 'mixed[]';
|
||||||
}
|
}
|
||||||
@ -151,4 +151,14 @@ final class ModelRegistry
|
|||||||
return $type->getBuiltinType();
|
return $type->getBuiltinType();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getCollectionValueType(Type $type): ?Type
|
||||||
|
{
|
||||||
|
// BC layer, this condition should be removed after removing support for symfony < 5.3
|
||||||
|
if (!method_exists($type, 'getCollectionValueTypes')) {
|
||||||
|
return $type->getCollectionValueType();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $type->getCollectionValueTypes()[0] ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr
|
|||||||
|
|
||||||
public function describe(array $types, OA\Schema $property, array $groups = null)
|
public function describe(array $types, OA\Schema $property, array $groups = null)
|
||||||
{
|
{
|
||||||
$type = $types[0]->getCollectionValueType();
|
// BC layer for symfony < 5.3
|
||||||
|
$type = method_exists($types[0], 'getCollectionValueTypes') ?
|
||||||
|
($types[0]->getCollectionValueTypes()[0] ?? null) :
|
||||||
|
$types[0]->getCollectionValueType();
|
||||||
if (null === $type) {
|
if (null === $type) {
|
||||||
throw new UndocumentedArrayItemsException();
|
throw new UndocumentedArrayItemsException();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,17 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist
|
|||||||
|
|
||||||
public function describe(array $types, OA\Schema $property, array $groups = null)
|
public function describe(array $types, OA\Schema $property, array $groups = null)
|
||||||
{
|
{
|
||||||
$type = new Type($types[0]->getBuiltinType(), false, $types[0]->getClassName(), $types[0]->isCollection(), $types[0]->getCollectionKeyType(), $types[0]->getCollectionValueType()); // ignore nullable field
|
$type = new Type(
|
||||||
|
$types[0]->getBuiltinType(),
|
||||||
|
false,
|
||||||
|
$types[0]->getClassName(),
|
||||||
|
$types[0]->isCollection(),
|
||||||
|
$types[0]->getCollectionKeyType(),
|
||||||
|
// BC layer for symfony < 5.3
|
||||||
|
method_exists($types[0], 'getCollectionValueTypes') ?
|
||||||
|
($types[0]->getCollectionValueTypes()[0] ?? null) :
|
||||||
|
$types[0]->getCollectionValueType()
|
||||||
|
); // ignore nullable field
|
||||||
|
|
||||||
if ($types[0]->isNullable()) {
|
if ($types[0]->isNullable()) {
|
||||||
$property->nullable = true;
|
$property->nullable = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user