nextapps/laravel-swagger-ui
最新稳定版本:1.2.0
Composer 安装命令:
composer require nextapps/laravel-swagger-ui
包简介
Add Swagger UI to a Laravel application.
README 文档
README
This package makes it easy to make your project's Swagger (OpenAPI v3 JSON or YAML) file accessible in a Swagger UI right in your Laravel application.
The Swagger UI will automatically use your current project environment. It will set your api's base url to the active base url. Possible oauth2 configuration, such as urls and client-id/client-secret, can also be injected in Swagger UI via the configuration file.
Installation
You can install the package via composer:
composer require wotz/laravel-swagger-ui
After installing Laravel Swagger UI, publish its service provider and configuration file using the swagger-ui:install Artisan command.
php artisan swagger-ui:install
Usage
The Swagger UI is exposed at /swagger. By default, you will only be able to access it in the local environment. Within your app/Providers/SwaggerUiServiceProvider.php file, there is a gate method. This authorization gate controls access to Swagger UI in non-local environments. You can modify this gate as needed to restrict access to your Swagger UI and Swagger (OpenAPI v3) file:
/** * Register the Swagger UI gate. * * This gate determines who can access Swagger UI in non-local environments. * * @return void */ protected function gate() { Gate::define('viewSwaggerUI', function ($user = null) { return in_array(optional($user)->email, [ // ]); }); }
In the published config/swagger-ui.php file, you edit the path to the Swagger UI and the location of the Swagger (OpenAPI v3) file. By default, the package expects to find the OpenAPI file in 'resources/swagger' directory. You can also provide an url if the OpenAPI file is not present in the Laravel project itself.
This is also where you can define multiple versions for the same api.
// in config/swagger-ui.php return [ // ... 'path' => 'swagger', 'versions' => [ 'v1' => resource_path('swagger/openapi.json') ], // ... ];
By default the package will customize the server url and the oauth urls in the OpenAPI file to the base url of the Laravel application. This can be disabled in the config.
// in config/swagger-ui.php return [ // ... 'modify_file' => true, // ... ];
You can also set an oauth client ID and client secret. These values will be automatically prefilled in the authentication view in Swagger UI.
// in config/swagger-ui.php return [ // ... 'oauth' => [ 'token_path' => 'oauth/token', 'refresh_path' => 'oauth/token', 'authorization_path' => 'oauth/authorize', 'client_id' => env('SWAGGER_UI_OAUTH_CLIENT_ID'), 'client_secret' => env('SWAGGER_UI_OAUTH_CLIENT_SECRET'), ]; // ... ];
Testing
composer test
Linting
composer lint
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email gunther.debrauwer@whoownsthezebra.be instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
nextapps/laravel-swagger-ui 适用场景与选型建议
nextapps/laravel-swagger-ui 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 328.07k 次下载、GitHub Stars 达 220, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「swagger」 「swagger-ui」 「openapi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nextapps/laravel-swagger-ui 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nextapps/laravel-swagger-ui 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nextapps/laravel-swagger-ui 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A silex service provider that integrates swagger-php 2.0 into silex
Swagger UI module for ZF2
OpenApi(Swagger) 3.0 package for Lumen 5.5+ and Laravel 5.5+ with REDOC UI and SwaggerUI 3
Want the swagger ui without having to set it up. Just install this package.
This Laravel/Voyager module adds REST Api Auth to Voyager.
Yii2 Swagger UI
统计信息
- 总下载量: 328.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 221
- 点击次数: 14
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 未知