DarkaOnLine / L5-Swagger

OpenApi or Swagger integration to Laravel
https://github.com/DarkaOnLine/L5-Swagger
MIT License
2.64k stars 394 forks source link

Laravel telescope local-only + default config = error `Class "Laravel\Telescope\TelescopeApplicationServiceProvider" not found` #535

Open dvdheiden opened 1 year ago

dvdheiden commented 1 year ago

Description:

Not completely an issue of this package, but the combination of Laravel Telescope in local-only mode (see: https://laravel.com/docs/9.x/telescope#local-only-installation) and the default config of this package could result an error when generating the docs:

In TelescopeServiceProvider.php line 10:

  [Error]                                                                  
  Class "Laravel\Telescope\TelescopeApplicationServiceProvider" not found  

Steps To Reproduce:

  1. Install Laravel.
  2. Install Laravel Telescope in local only mode.
  3. Install this package ❤️ .
  4. Run composer install --no-dev to exclude development packages.
  5. Set app to any other environment than local in your .env.
  6. Run the command: l5-swagger:generate and see error.

Cause

When running Laravel Telescope in local only mode, the package won't be installed on any other environment than local. The TelescopeServiceProvider won't be loaded, but still extends a non-existing class (from the Laravel Telescope package). The error occurs because the default config of this package scans the whole app folder, so also this service provider.

Possible solution

A few possible solutions might be:

/*
 * Absolute path to directories that should be exclude from scanning
 */
 'excludes' => [
    base_path('app/Providers'),
],
/*
 * Absolute paths to directory containing the swagger annotations are stored.
 */
 'annotations' => [
     base_path('app/Http'),
     base_path('app/Models'),
 ],

I am uncertain if this package should do anything about this, but at least this issue might help some (and probably my future self) with solving that error.

Astriel commented 1 week ago

Facing this problem on production too. I had to generate the doc on my localhost then push it to the production server.