kevupton / auto-swagger-ui
想要使用swagger ui而不必进行设置。只需安装此包即可。
v0.1.3
2017-10-11 05:13 UTC
Requires
- php: >=5.3
- kevupton/laravel-swagger: ^1.4
Requires (Dev)
- barryvdh/laravel-ide-helper: ^2.2
- laravel/framework: 5.5.*
- laravel/lumen-framework: 5.5.*
README
只需几秒钟即可为您的项目添加swagger文档。只需安装包和服务提供者,可选地添加配置文件,然后BAM,您现在就有了swagger ui端点。
它还与swagger php注释集成,允许您扫描注释并在指定的端点生成json对象。1,2,3,太多的swagger。 ;)
安装
composer require kevupton/auto-swagger-ui
设置
添加到服务提供者
Laravel
在config/app.php
中,在providers
中添加
\Kevupton\AutoSwaggerUI\Providers\AutoSwaggerUIServiceProvider::class,
Lumen
在bootstrap/app.php
中添加
$app->register(\Kevupton\AutoSwaggerUI\Providers\AutoSwaggerUIServiceProvider::class);
运行
一旦注册了服务提供者,您就可以访问swagger页面,在
http://{my-host}/api/swagger
或者json在
http://{my-host}/api/swagger.json
配置
此包可以通过发布配置或从供应商文件中复制配置来进行配置。要发布
php artisan vendor:publish
配置
<?php return array( // whether or not the swagger ui is enabled 'ui_enabled' => env('SWAGGER_UI_ENABLED', true), // the path to the swagger ui implementation. By default will use its own swagger ui 'path' => env('SWAGGER_UI_PATH'), 'urls' => [ // where the swagger ui will be located 'ui' => env('SWAGGER_UI_URL', '/api/swagger'), // where the json will be located 'json' => env('SWAGGER_JSON_URL', '/api/swagger.json') ], // whether or not to enable the swagger scanner 'scanner_enabled' => env('SWAGGER_SCAN_ENABLED', true), 'scanner' => [ // if you want to enable swagger scan then specify an endpoint 'output_url' => env('SWAGGER_SCANNER_OUTPUT_URL', '/api/swagger.json'), // the directory to scan 'paths' => env('SWAGGER_SCANNER_PATH', '/app/Http/Controllers'), // the default scanner which passes the json 'handler' => env('SWAGGER_SCANNER_HANDLER', '\Kevupton\LaravelSwagger\scan'), // the options that is passed into the scanner 'options' => [ // the models to include in the scan 'models' => [] ], // how long to save the scanned json for 'cache_duration' => env('SWAGGER_SCANNER_CACHE_DURATION', null), // headers in the JSON response (for CORS) 'headers' => [ 'Access-Control-Allow-Origin: *', 'Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE', 'Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization' ] ] );
注意:Lumen可能需要将此包中的配置文件复制到swagger.php
,并在bootstrap/app.js
中注册配置$app->configure('swagger');
。
NGINX您可能需要调整配置文件,以便使用以下行进行文件未找到的重定向
try_files $uri /index.php;
示例
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|svg|woff|woff2|ttf)$ {
try_files $uri /index.php;
expires 1M;
access_log off;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)$ {
try_files $uri /index.php;
expires 7d;
access_log off;
add_header Cache-Control "public";
}