api-platform / create-client

Generate React or Vue.js-based Progressive Web Apps from an Hydra-enabled API. Also support React Native.
https://api-platform.com/docs/client-generator/
MIT License
369 stars 132 forks source link

Enum types are not being generated by the Typescript Generator #366

Open gigo6000 opened 1 year ago

gigo6000 commented 1 year ago

API Platform version(s) affected: 3.0

Description
I'm using the Typescript Generator to generate some interfaces and I have some enum types in the Entity, for example:

<?php
//Enum
namespace App\Enum;

enum Gender: string
{
    case FEMALE = 'female';
    case MALE = 'male';
}
<?php
// Entity
class Person
{
    ...
    #[ORM\Column(type: "string", length: 6, nullable: true, enumType: Gender::class)]
    private $gender;
    ...

but when I generate the interfaces, they are generated as type any.

How to reproduce
Create an entity with an enum type. Use the Typescript generator to generate the corresponding interface:

npm init @api-platform/client http://localhost/api src/ -- --generator typescript

The interface generated will be of type any instead of having the proper enum type:

export interface Person {
 ...
 gender?: any;
 ...
}

Possible Solution

The generator should generate the corresponding enum and implement it in the interface:

export interface Person {
 ...
 gender?: gender;
 ...
}

export enum gender {
    FEMALE = 'female',
    MALE = 'male',
}

Additional Context