api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.43k stars 866 forks source link

Doc: PHPDoc return tag array type parse error #4190

Closed soullivaneuh closed 3 years ago

soullivaneuh commented 3 years ago

API Platform version(s) affected: 2.6.3 (after update from 2.5.3)

Description

The swagger decorator does not like array<T,U> phpdoc annotation on function @return tags.

How to reproduce

Create a function that return an array with the following annotation:

/**
 * @Groups("challenges")
 *
 * @return array<string, mixed[]>
 */
public function getChallenges(): array
{
    // Stuff.
}

On doc generation, you will have the following error:

ReflectionException:
Class rray<string,array> does not exist

  at vendor/php/api-platform/core/src/JsonSchema/SchemaFactory.php:257
  at ReflectionClass->__construct('rray&lt;string,array&gt;')
     (vendor/php/api-platform/core/src/JsonSchema/SchemaFactory.php:257)
  at ApiPlatform\Core\JsonSchema\SchemaFactory->buildDefinitionName('rray&lt;string,array&gt;', 'json', 'output', null, null, array())
     (vendor/php/api-platform/core/src/JsonSchema/SchemaFactory.php:84)
  at ApiPlatform\Core\JsonSchema\SchemaFactory->buildSchema('rray&lt;string,array&gt;', 'json', 'output', null, null, object(Schema), array())
     (vendor/php/api-platform/core/src/JsonSchema/TypeFactory.php:149)
  at ApiPlatform\Core\JsonSchema\TypeFactory->getClassType('rray&lt;string,array&gt;', 'json', null, array(), object(Schema))
     (vendor/php/api-platform/core/src/JsonSchema/TypeFactory.php:88)
  at ApiPlatform\Core\JsonSchema\TypeFactory->makeBasicType(object(Type), 'json', null, array(), object(Schema))
     (vendor/php/api-platform/core/src/JsonSchema/TypeFactory.php:71)
  at ApiPlatform\Core\JsonSchema\TypeFactory->getType(object(Type), 'json', null, array(), object(Schema))
     (vendor/php/api-platform/core/src/JsonSchema/SchemaFactory.php:242)
  at ApiPlatform\Core\JsonSchema\SchemaFactory->buildPropertySchema(object(Schema), 'SslCertificate', 'challenges', object(PropertyMetadata), array(), 'json')
     (vendor/php/api-platform/core/src/JsonSchema/SchemaFactory.php:156)
  at ApiPlatform\Core\JsonSchema\SchemaFactory->buildSchema('App\\Entity\\SslCertificate', 'json', 'output', 'item', 'get', object(Schema), array(), false)

Replacing the @return tag type by mixed[] "solves" the issue.

Possible Solution

Additional Context

Was working on 2.5.3. I don't know what else to put for now, feel free to ask for details.

guilliamxavier commented 3 years ago

Seems to be the same issue as https://github.com/api-platform/api-platform/issues/1439, probably related to https://github.com/symfony/symfony/pull/37559 (implemented in Symfony 5.2)

soullivaneuh commented 3 years ago

Yes it is, closing as duplicate of https://github.com/api-platform/api-platform/issues/1439

Thanks for the hint!