dedoc / scramble

Modern Laravel OpenAPI (Swagger) documentation generator. No PHPDoc annotations required.
https://scramble.dedoc.co/
MIT License
965 stars 87 forks source link

PHP native Enum type not supported #432

Open davidmohamedfr opened 1 week ago

davidmohamedfr commented 1 week ago

Hi ! I'm having a "Path cannot be empty" error on docs generation because i'm using native Enum class from PHP

From what I've investigate, trouble come from MethodReflector:getReflection using new ReflectionMethod when reflection for Enum need to be used with new ReflectionEnum

Hope this will help someone fix this issue.

romalytvynenko commented 1 week ago

@davidmohamedfr please share some code examples so I can reproduce

davidmohamedfr commented 1 week ago

This is an example.

I'm in PHP 8.3.2, using Laravel Framework 11.2.0 and Scramble 0.10.13

enum MyEnum: int
{
    case TITI = 1;
    case TOTO = 2;

    public function label(): string
    {
        return match ($this) {
            Origin::TITI => 'titi',
            Origin::TOTO => 'toto',
        };
    }
}
enum CarsEnum: int
{
    case TOYOTA= 1;
    case FERRARI = 2;
}
   /**
     * @param array<string, mixed> $data
     */
    public static function create(array $data)
    {
        return new DTO(
            titi: MyEnum::from($data['titi']),
            cars: CarsEnum::from($data['cars']),
        );
    }
romalytvynenko commented 1 week ago

@davidmohamedfr I still don't understand how your controller looks like for the api route that fails

romalytvynenko commented 1 week ago

@davidmohamedfr Please share the code that I can use to reproduce. This includes everything that is needed to have the same issue