Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rdavaillaud opened this issue Nov 29, 2018 · 1 comment

Comments

@rdavaillaud
Copy link
Contributor

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
Copy link
Member

stood commented Nov 30, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants