core
core copied to clipboard
Class "self" does not exist
API Platform version(s) affected: v2.7.16
Description
Generation of swagger fails with exception 'Class "self" does not exist' when used enum contains valid phpdoc block on public method when key-word self is used to describe values of returned array.
How to reproduce
Add static method to enum which is responsible for providing of some cases. And phpdoc block with description of array values via key-word self.
Example:
enum MyEnum: string
{
case first = 'first';
case second = 'second';
/**
* @return self[]
*/
public static function getSomeCases(): array
{
return [self::first];
}
}
It works fine when I change key-word "self" to name of enum.
enum MyEnum: string
{
case first = 'first';
case second = 'second';
/**
* @return MyEnum[]
*/
public static function getSomeCases(): array
{
return [self::first];
}
}
Possible Solution
Additional Context
Stack trace:
#24 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(234): ReflectionClass::__construct
#23 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(234): ApiPlatform\JsonSchema\SchemaFactory::buildDefinitionName
#22 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(79): ApiPlatform\JsonSchema\SchemaFactory::buildSchema
#21 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(155): ApiPlatform\JsonSchema\TypeFactory::getClassType
#20 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(88): ApiPlatform\JsonSchema\TypeFactory::makeBasicType
#19 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(75): ApiPlatform\JsonSchema\TypeFactory::getType
#18 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(71): ApiPlatform\JsonSchema\TypeFactory::getType
#17 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(216): ApiPlatform\JsonSchema\SchemaFactory::buildPropertySchema
#16 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(140): ApiPlatform\JsonSchema\SchemaFactory::buildSchema
#15 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(155): ApiPlatform\JsonSchema\TypeFactory::getClassType
#14 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(88): ApiPlatform\JsonSchema\TypeFactory::makeBasicType
#13 /vendor/api-platform/core/src/JsonSchema/TypeFactory.php(75): ApiPlatform\JsonSchema\TypeFactory::getType
#12 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(216): ApiPlatform\JsonSchema\SchemaFactory::buildPropertySchema
#11 /vendor/api-platform/core/src/JsonSchema/SchemaFactory.php(140): ApiPlatform\JsonSchema\SchemaFactory::buildSchema
#10 /vendor/api-platform/core/src/OpenApi/Factory/OpenApiFactory.php(270): ApiPlatform\OpenApi\Factory\OpenApiFactory::collectPaths
#9 /vendor/api-platform/core/src/OpenApi/Factory/OpenApiFactory.php(103): ApiPlatform\OpenApi\Factory\OpenApiFactory::__invoke
Hi, 2.7 is not supported and has security issues please upgrade. Type matching is being revised using the new TypeInfo component, not sure it'll ever fix this issue though.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.