matchory / herodot

A versatile documentation generator for APIs built with Laravel.
MIT License
6 stars 0 forks source link

php artisan herodot:generate fails with a __PHP_Incomplete_Class given #1

Closed HerrLevin closed 3 years ago

HerrLevin commented 3 years ago

When I run php artisan herodot:generate herodot fails with an error that a __PHP_Incomplete_Class was given instead of a Matchory\Herodot\Contracts\Endpoint. Trying to fix it myself I realized that all routes retrieved in Support/Generator.php via $endpoints = $this->processRoutes($routes); are of type __PHP_Incomplete_Class(Matchory\Herodot\Support\Structures\Endpoint).

I'm using Laravel 8.24.0 with PHP 8.0.1

This is my console output + stack trace of the logs

 php artisan herodot:generate

   TypeError 

  Matchory\Herodot\Support\Printing\OpenApiPrinter::Matchory\Herodot\Support\Printing\{closure}(): Argument #1 ($endpoint) must be of type Matchory\Herodot\Contracts\Endpoint, __PHP_Incomplete_Class given, called in /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Collections/Collection.php on line 434

  at vendor/matchory/herodot/src/Support/Printing/OpenApiPrinter.php:155
    151▕     public function print(Collection $endpoints): void
    152▕     {
    153▕         $grouped = $endpoints
    154▕             ->groupBy(
  ➜ 155▕                 fn(Endpoint $endpoint) => $endpoint->getGroup() ?? ''
    156▕             )
    157▕             ->toArray();
    158▕ 
    159▕         $spec = new OpenApi([]);

      +19 vendor frames 
  20  artisan:37
     Illuminate\Foundation\Console\Kernel::handle()
[2021-02-05 23:10:02] local.ERROR: Matchory\Herodot\Support\Printing\OpenApiPrinter::Matchory\Herodot\Support\Printing\{closure}(): Argument #1 ($endpoint) must be of type Matchory\Herodot\Contracts\Endpoint, __PHP_Incomplete_Class given, called in /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Collections/Collection.php on line 434 {"exception":"[object] (TypeError(code: 0): Matchory\\Herodot\\Support\\Printing\\OpenApiPrinter::Matchory\\Herodot\\Support\\Printing\\{closure}(): Argument #1 ($endpoint) must be of type Matchory\\Herodot\\Contracts\\Endpoint, __PHP_Incomplete_Class given, called in /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Collections/Collection.php on line 434 at /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Support/Printing/OpenApiPrinter.php:155)
[stacktrace]
#0 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Collections/Collection.php(434): Matchory\\Herodot\\Support\\Printing\\OpenApiPrinter->Matchory\\Herodot\\Support\\Printing\\{closure}()
#1 /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Support/Printing/OpenApiPrinter.php(156): Illuminate\\Support\\Collection->groupBy()
#2 /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Support/Printing/DocumentationWriter.php(42): Matchory\\Herodot\\Support\\Printing\\OpenApiPrinter->print()
#3 /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Support/Generator.php(155): Matchory\\Herodot\\Support\\Printing\\DocumentationWriter->write()
#4 /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Support/Generator.php(72): Matchory\\Herodot\\Support\\Generator->writeOutput()
#5 /home/herrlevin_/PhpstormProjects/traewelling/vendor/matchory/herodot/src/Console/Commands/GenerateCommand.php(78): Matchory\\Herodot\\Support\\Generator->generate()
#6 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(36): Matchory\\Herodot\\Console\\Commands\\GenerateCommand->handle()
#7 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Container/Util.php(40): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure()
#9 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod()
#10 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Container/Container.php(610): Illuminate\\Container\\BoundMethod::call()
#11 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Console/Command.php(136): Illuminate\\Container\\Container->call()
#12 /home/herrlevin_/PhpstormProjects/traewelling/vendor/symfony/console/Command/Command.php(255): Illuminate\\Console\\Command->execute()
#13 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Console/Command.php(121): Symfony\\Component\\Console\\Command\\Command->run()
#14 /home/herrlevin_/PhpstormProjects/traewelling/vendor/symfony/console/Application.php(971): Illuminate\\Console\\Command->run()
#15 /home/herrlevin_/PhpstormProjects/traewelling/vendor/symfony/console/Application.php(290): Symfony\\Component\\Console\\Application->doRunCommand()
#16 /home/herrlevin_/PhpstormProjects/traewelling/vendor/symfony/console/Application.php(166): Symfony\\Component\\Console\\Application->doRun()
#17 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Console/Application.php(93): Symfony\\Component\\Console\\Application->run()
#18 /home/herrlevin_/PhpstormProjects/traewelling/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(129): Illuminate\\Console\\Application->run()
#19 /home/herrlevin_/PhpstormProjects/traewelling/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle()
#20 {main}
"} 
Radiergummi commented 3 years ago

Hi @HerrLevin, Herodot is still in active development currently, so I'm not too surprised there's some hiccups.. This seems to originate from the caching though, so by passing --force to the generate command, it should properly generate the OpenAPI docs.
I'm looking into this now, thanks for reporting!

Radiergummi commented 3 years ago

Fixed in c5eea95

HerrLevin commented 3 years ago

Oh nice, thank you!