mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-11 18:16:13 +03:00
Improve "no describer found" error message (#1979)
This commit is contained in:
parent
1302bc7568
commit
f8c030d096
@ -100,7 +100,11 @@ final class ModelRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (null === $schema) {
|
if (null === $schema) {
|
||||||
throw new \LogicException(sprintf('Schema of type "%s" can\'t be generated, no describer supports it.', $this->typeToString($model->getType())));
|
$errorMessage = sprintf('Schema of type "%s" can\'t be generated, no describer supports it.', $this->typeToString($model->getType()));
|
||||||
|
if (Type::BUILTIN_TYPE_OBJECT === $model->getType()->getBuiltinType() && !class_exists($className = $model->getType()->getClassName())) {
|
||||||
|
$errorMessage .= sprintf(' Class "\\%s" does not exist, did you forget a use statement, or typed it wrong?', $className);
|
||||||
|
}
|
||||||
|
throw new \LogicException($errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +178,7 @@ final class ModelRegistry
|
|||||||
private function typeToString(Type $type): string
|
private function typeToString(Type $type): string
|
||||||
{
|
{
|
||||||
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 !== $collectionType = $this->getCollectionValueType($type)) {
|
if (null !== $collectionType = $this->getCollectionValueType($type)) {
|
||||||
return $this->typeToString($collectionType).'[]';
|
return $this->typeToString($collectionType).'[]';
|
||||||
|
@ -234,7 +234,20 @@ class ModelRegistryTest extends TestCase
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
[new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true), 'mixed[]'],
|
[new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true), 'mixed[]'],
|
||||||
[new Type(Type::BUILTIN_TYPE_OBJECT, false, self::class), self::class],
|
[new Type(Type::BUILTIN_TYPE_OBJECT, false, self::class), '\\'.self::class],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUnsupportedTypeExceptionWithNonExistentClass()
|
||||||
|
{
|
||||||
|
$className = DoesNotExist::class;
|
||||||
|
$type = new Type(Type::BUILTIN_TYPE_OBJECT, false, $className);
|
||||||
|
|
||||||
|
$this->expectException('\LogicException');
|
||||||
|
$this->expectExceptionMessage(sprintf('Schema of type "\%s" can\'t be generated, no describer supports it. Class "\Nelmio\ApiDocBundle\Tests\Model\DoesNotExist" does not exist, did you forget a use statement, or typed it wrong?', $className));
|
||||||
|
|
||||||
|
$registry = new ModelRegistry([], new OA\OpenApi([]));
|
||||||
|
$registry->register(new Model($type));
|
||||||
|
$registry->registerSchemas();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user