svensp/laravel-swagger
Composer 安装命令:
composer require svensp/laravel-swagger
包简介
generate openapi api-docs.json from laravel route definitions and annotated .yml file
README 文档
README
this package tries to assist in generating api-doc.yml files for your laravel based apis.
It does not try to generate the whole api-doc.yml for you and thus does not function as complete abstraction layer for
the openapi specification. Instead think of it as route:list that makes sure your open-api.yml files have all routes
present and notify you of routes present in the open-api.yml but not in your laravel routes.
- the controller in which a route resides decides the open-api.yml the route appears in via the @apidoc phpdoc entry
- multiple controllers can use the same open-api.yml
Install
to install the package simply require it with composer:
composer require svensp/laravel-swagger
Use
Annotate the controllers which should appear in an open-api.yml with
/**
* Class AuthController
* @apidoc path/to/your/open-api.yml
*/
class AuthController {
...
and have them created with
./artin open-api:generate
It is however recommended to publish the config file and use an alias:
./artisan vendor:publish --provider=LaravelSwagger\LaravelSwaggerProvider
The default settings map @ to app_path(), personally I map the name default to resource_path('/open-api.yml')
/**
* Class AuthController
* @apidoc @/resources/open-api.yml
* OR
* @apidoc default
*
*/
class AuthController {
...
Tags
If you use the same open-api.yml for multiple controllers then you probably want to have the same tags set for all
routes of the same controller. You an use the @apitags phpdoc directive to have this done automatically for you:
/**
* Class AuthController
* @apidoc default
* @apitags auth
*
*/
class AuthController {
...
/**
* Class NewsController
* @apidoc default
* @apitags news
*
*/
class NewsController {
...
the list of tags is parsed as comma separated list.
Roadmap
- (maybe) add parameters defined in FormRequests used by a controller function
Use outside of Laravel
While I have not split the package in its laravel and open-api components it is possible to use it outside of Laravel.
Simply instantiate the LaravelSwagger\OpenApi\Updater and pass an array of DefinedRoutes to its update function.
Creating DefinedRoutes from your framework of choice is up to you, as is passing
- templates usually loaded from the config
- aliases usually loaded from the config
- callbacks - set in the laravel command to echo having foud a controller without @apidoc directive or routes in the open-api.yml which are no longer present in your DefinedRoutes
svensp/laravel-swagger 适用场景与选型建议
svensp/laravel-swagger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 408 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 svensp/laravel-swagger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 svensp/laravel-swagger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 408
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-05