From 88288d08d15165c82667205328db580a34dc7b55 Mon Sep 17 00:00:00 2001 From: Darius Matulionis Date: Mon, 12 Feb 2018 08:52:16 +0200 Subject: [PATCH] Remove redundant commands and update installation instructions Also remove associated tests and improve the Service Provider to follow Laravel documentation. Update installation instructions update readme and leave publish test --- README.md | 17 +++++++------ src/Console/PublishCommand.php | 35 --------------------------- src/Console/PublishConfigCommand.php | 36 ---------------------------- src/Console/PublishViewsCommand.php | 36 ---------------------------- src/L5SwaggerServiceProvider.php | 29 +++------------------- tests/ConsoleTest.php | 24 ++----------------- 6 files changed, 13 insertions(+), 164 deletions(-) delete mode 100644 src/Console/PublishCommand.php delete mode 100644 src/Console/PublishConfigCommand.php delete mode 100644 src/Console/PublishViewsCommand.php diff --git a/README.md b/README.md index fc9bd15..a131737 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,6 @@ This package is a wrapper of [Swagger-php](https://github.com/zircote/swagger-ph Installation ============ -For Swagger 2.0 - Laravel | Swagger UI| OpenAPI Spec compatibility | L5-Swagger :---------|:----------|:---------------------------|:---------- 5.1.x | 2.2 | 1.1, 1.2, 2.0 | ```php composer require "darkaonline/l5-swagger:~3.0" ``` @@ -26,12 +24,14 @@ For Swagger 2.0 5.5.x | 3 | 2.0 | ```php composer require "darkaonline/l5-swagger:5.5.*" ``` 5.6.x | 3 | 2.0 | ```php composer require "darkaonline/l5-swagger:5.6.*" ``` +You can publish L5-Swagger's config and view files into your project by running: -For Swagger 1.0 -```php -composer require darkaonline/l5-swagger +```bash +$ php artisan vendor:publish --provider 'L5Swagger\L5SwaggerServiceProvider' ``` +For Laravel >=5.5, no need to manually add `L5SwaggerServiceProvider` into config. It uses package auto discovery feature. Skip this if you are on >=5.5, if not: + Open your `AppServiceProvider` (located in `app/Providers`) and add this line in `register` function ```php $this->app->register(\L5Swagger\L5SwaggerServiceProvider::class); @@ -41,8 +41,6 @@ or open your `config/app.php` and add this line in `providers` section L5Swagger\L5SwaggerServiceProvider::class, ``` -For Laravel 5.5, no need to manually add `L5SwaggerServiceProvider` into config. It uses package auto discovery feature. - Using Swagger UI with Passport ============ The easiest way to build and test your Laravel-based API using Swagger-php is to use Passport's `CreateFreshApiToken` middleware. This middleware, built into Laravel's core, adds a cookie to all responses, and the cookie authenticates all subsequent requests through Passport's `TokenGuard`. @@ -50,8 +48,7 @@ The easiest way to build and test your Laravel-based API using Swagger-php is to To get started, first publish L5-Swagger's config and view files into your own project: ```bash -$ php artisan l5-swagger:publish-config -$ php artisan l5-swagger:publish-views +$ php artisan vendor:publish --provider 'L5Swagger\L5SwaggerServiceProvider' ``` Next, edit your `config/l5-swagger.php` configuration file. Locate the `l5-swagger.routes.middleware` section, and add the following middleware list to the `api` route: @@ -132,10 +129,12 @@ Migrate from 3.0|4.0 to 5.0 Configuration ============ +### For versions < 5.5 - Run `l5-swagger:publish` to publish everything - Run `l5-swagger:publish-config` to publish configs (`config/l5-swagger.php`) - Run `l5-swagger:publish-assets` to publish swagger-ui to your public folder (`public/vendor/l5-swagger`) - Run `l5-swagger:publish-views` to publish views (`resources/views/vendor/l5-swagger`) - only for versions <= 4.0 +### For all versions - Run `l5-swagger:generate` to generate docs or set `generate_always` param to `true` in your config or .env file Swagger-php diff --git a/src/Console/PublishCommand.php b/src/Console/PublishCommand.php deleted file mode 100644 index bed8f42..0000000 --- a/src/Console/PublishCommand.php +++ /dev/null @@ -1,35 +0,0 @@ -info('Publishing all files'); - $this->call('vendor:publish', [ - '--provider' => 'L5Swagger\L5SwaggerServiceProvider', - ]); - } -} diff --git a/src/Console/PublishConfigCommand.php b/src/Console/PublishConfigCommand.php deleted file mode 100644 index 8387001..0000000 --- a/src/Console/PublishConfigCommand.php +++ /dev/null @@ -1,36 +0,0 @@ -info('Publish config files'); - $this->call('vendor:publish', [ - '--provider' => 'L5Swagger\L5SwaggerServiceProvider', - '--tag' => ['config'], - ]); - } -} diff --git a/src/Console/PublishViewsCommand.php b/src/Console/PublishViewsCommand.php deleted file mode 100644 index e821e92..0000000 --- a/src/Console/PublishViewsCommand.php +++ /dev/null @@ -1,36 +0,0 @@ -info('Publishing view files'); - $this->call('vendor:publish', [ - '--provider' => 'L5Swagger\L5SwaggerServiceProvider', - '--tag' => ['views'], - ]); - } -} diff --git a/src/L5SwaggerServiceProvider.php b/src/L5SwaggerServiceProvider.php index a5f4c2c..52644b2 100644 --- a/src/L5SwaggerServiceProvider.php +++ b/src/L5SwaggerServiceProvider.php @@ -2,11 +2,8 @@ namespace L5Swagger; -use L5Swagger\Console\PublishCommand; use Illuminate\Support\ServiceProvider; use L5Swagger\Console\GenerateDocsCommand; -use L5Swagger\Console\PublishViewsCommand; -use L5Swagger\Console\PublishConfigCommand; class L5SwaggerServiceProvider extends ServiceProvider { @@ -32,10 +29,12 @@ public function boot() ], 'views'); //Include routes - \Route::group(['namespace' => 'L5Swagger'], function ($router) { require __DIR__.'/routes.php'; }); + + //Register commands + $this->commands([GenerateDocsCommand::class]); } /** @@ -48,28 +47,9 @@ public function register() $configPath = __DIR__.'/../config/l5-swagger.php'; $this->mergeConfigFrom($configPath, 'l5-swagger'); - $this->app->singleton('command.l5-swagger.publish', function () { - return new PublishCommand(); - }); - - $this->app->singleton('command.l5-swagger.publish-config', function () { - return new PublishConfigCommand(); - }); - - $this->app->singleton('command.l5-swagger.publish-views', function () { - return new PublishViewsCommand(); - }); - $this->app->singleton('command.l5-swagger.generate', function () { return new GenerateDocsCommand(); }); - - $this->commands( - 'command.l5-swagger.publish', - 'command.l5-swagger.publish-config', - 'command.l5-swagger.publish-views', - 'command.l5-swagger.generate' - ); } /** @@ -80,9 +60,6 @@ public function register() public function provides() { return [ - 'command.l5-swagger.publish', - 'command.l5-swagger.publish-config', - 'command.l5-swagger.publish-views', 'command.l5-swagger.generate', ]; } diff --git a/tests/ConsoleTest.php b/tests/ConsoleTest.php index ab1ebbb..9701513 100644 --- a/tests/ConsoleTest.php +++ b/tests/ConsoleTest.php @@ -26,29 +26,9 @@ public function canPublish() { $this->setAnnotationsPath(); - Artisan::call('l5-swagger:publish'); + Artisan::call('vendor:publish', ['--provider' => "'L5Swagger\L5SwaggerServiceProvider'"]); $this->assertTrue(file_exists(config_path('l5-swagger.php'))); - $this->assertTrue(file_exists(config('l5-swagger.paths.views').'/index.blade.php')); - } - - /** @test */ - public function canPublishConfig() - { - $this->setAnnotationsPath(); - - Artisan::call('l5-swagger:publish-config'); - - $this->assertTrue(file_exists(config_path('l5-swagger.php'))); - } - - /** @test */ - public function canPublishViews() - { - $this->setAnnotationsPath(); - - Artisan::call('l5-swagger:publish-views'); - - $this->assertTrue(file_exists(config('l5-swagger.paths.views').'/index.blade.php')); + $this->assertTrue(file_exists(config('l5-swagger.paths.views') . '/index.blade.php')); } }