mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
parent
aa18c6c83b
commit
c0b57fd371
@ -126,8 +126,8 @@ final class ModelRegistry
|
||||
|
||||
private function getTypeShortName(Type $type): string
|
||||
{
|
||||
if (null !== $type->getCollectionValueType()) {
|
||||
return $this->getTypeShortName($type->getCollectionValueType()).'[]';
|
||||
if (null !== $collectionType = $this->getCollectionValueType($type)) {
|
||||
return $this->getTypeShortName($collectionType).'[]';
|
||||
}
|
||||
|
||||
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
||||
@ -144,8 +144,8 @@ final class ModelRegistry
|
||||
if (Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()) {
|
||||
return $type->getClassName();
|
||||
} elseif ($type->isCollection()) {
|
||||
if (null !== $type->getCollectionValueType()) {
|
||||
return $this->typeToString($type->getCollectionValueType()).'[]';
|
||||
if (null !== $collectionType = $this->getCollectionValueType($type)) {
|
||||
return $this->typeToString($collectionType).'[]';
|
||||
} else {
|
||||
return 'mixed[]';
|
||||
}
|
||||
@ -153,4 +153,14 @@ final class ModelRegistry
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,10 @@ class ArrayPropertyDescriber implements PropertyDescriberInterface, ModelRegistr
|
||||
|
||||
public function describe(Type $type, Schema $property, array $groups = null)
|
||||
{
|
||||
$type = $type->getCollectionValueType();
|
||||
// BC layer for symfony < 5.3
|
||||
$type = method_exists($type, 'getCollectionValueTypes') ?
|
||||
($type->getCollectionValueTypes()[0] ?? null) :
|
||||
$type->getCollectionValueType();
|
||||
if (null === $type) {
|
||||
throw new UndocumentedArrayItemsException();
|
||||
}
|
||||
|
@ -23,7 +23,19 @@ class ObjectPropertyDescriber implements PropertyDescriberInterface, ModelRegist
|
||||
|
||||
public function describe(Type $type, Schema $property, array $groups = null)
|
||||
{
|
||||
$type = new Type($type->getBuiltinType(), false, $type->getClassName(), $type->isCollection(), $type->getCollectionKeyType(), $type->getCollectionValueType()); // ignore nullable field
|
||||
$type = new Type(
|
||||
$type->getBuiltinType(),
|
||||
false,
|
||||
$type->getClassName(),
|
||||
$type->isCollection(),
|
||||
method_exists($type, 'getCollectionKeyTypes') ?
|
||||
($type->getCollectionKeyTypes()[0] ?? null) :
|
||||
$type->getCollectionKeyType(),
|
||||
// BC layer for symfony < 5.3
|
||||
method_exists($type, 'getCollectionValueTypes') ?
|
||||
($type->getCollectionValueTypes()[0] ?? null) :
|
||||
$type->getCollectionValueType()
|
||||
); // ignore nullable field
|
||||
|
||||
$property->setRef(
|
||||
$this->modelRegistry->register(new Model($type, $groups))
|
||||
|
Loading…
x
Reference in New Issue
Block a user