Skip to content

Commit

Permalink
Remove redundant commands and update installation instructions
Browse files Browse the repository at this point in the history
Also remove associated tests and improve the Service Provider to follow
Laravel documentation.

Update installation instructions

update readme and leave publish test
  • Loading branch information
DarkaOnLine committed Feb 12, 2018
1 parent fbb13f5 commit 88288d0
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 164 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" ```
Expand All @@ -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);
Expand All @@ -41,17 +41,14 @@ 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`.

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:
Expand Down Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions src/Console/PublishCommand.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Console/PublishConfigCommand.php

This file was deleted.

36 changes: 0 additions & 36 deletions src/Console/PublishViewsCommand.php

This file was deleted.

29 changes: 3 additions & 26 deletions src/L5SwaggerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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]);
}

/**
Expand All @@ -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'
);
}

/**
Expand All @@ -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',
];
}
Expand Down
24 changes: 2 additions & 22 deletions tests/ConsoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

0 comments on commit 88288d0

Please sign in to comment.