pomm-project / pomm-symfony-bridge

Pomm2 shared elements for profiler between Silex and Symfony.
8 stars 17 forks source link

PropertyInfo does'nt handle array sub type (varchar[], text[], int[]...) #41

Open rdavaillaud opened 5 years ago

rdavaillaud commented 5 years ago

Hi,

It seems that the PropertyInfo TypeExtractor does not handle array subtype.

In a structure like the following

<?php
namespace App\Model\Test\PublicSchema\AutoStructure;
use PommProject\ModelManager\Model\RowStructure;
class Asset extends RowStructure
{
    public function __construct()
    {
        $this
            ->setRelation('public.asset')
            ->setPrimaryKey(['id'])
            ->addField('id', 'int4')
            ->addField('typedarray', 'text[]')
            ;
    }
}

With API Plateform, when I want to generate the swagger file with: bin/console api:swagger:export --output=swagger_specification.json

It throws an error:

In FileLoader.php line 168:

  Invalid text[]  in . (which is being imported from "/var/www/config/routes/api_platform.yaml"). Make sure there is a loader supporting the "api_platform" type.  

In TypeExtractor.php line 93:

  Invalid text[]  

After some digging, in TypeExtractor.php, the function getPommType() does not get the proper array subtype.

    private function getPommType(Session $session, $sql_type)
    {
        $pomm_types = $session->getPoolerForType('converter')
            ->getConverterHolder()
            ->getTypesWithConverterName();

        if (!isset($pomm_types[$sql_type])) {
            throw new \RuntimeException("Invalid $sql_type");
        }

        return $pomm_types[$sql_type];
    }

If I replace with the code below, it works as expected.

    private function getPommType(Session $session, $sql_type)
    {
        $pomm_type = $session
            ->getClientUsingPooler('converter', $sql_type)
        ;

        if (!isset($pomm_type)) {
            throw new \RuntimeException("Invalid $sql_type ");
        }

        return $pomm_type;
    }

It seems to be multiple path to get a converter, I don't know if this is the right thing to do.

stood commented 5 years ago

For me the problem is the array have multiple definition.

The converter PgArray is capable to return if the type is an array or not :

if ($sql_type !== PgArray::getSubType($sql_type)) {
            $sql_type = 'array';
}

With this fix we keep the definition in this class.