Download the PHP package kaxiluo/swagger-laravel-code-generator without Composer
On this page you can find all versions of the php package kaxiluo/swagger-laravel-code-generator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kaxiluo/swagger-laravel-code-generator
More information about kaxiluo/swagger-laravel-code-generator
Files in kaxiluo/swagger-laravel-code-generator
Package swagger-laravel-code-generator
Short Description Automatically generate laravel models, resources, controllers, routes based on swagger documents
License MIT
Informations about the package swagger-laravel-code-generator
swagger-laravel-code-generator
根据swagger文档自动生成laravel模型,资源,控制器,路由
安装
使用方法
php artisan swagger-to-code:gen ./docs/your-openapi.yaml --ignored-schema-regular=^Error* --all --force
参数:
- yaml文件的相对路径(相对于工程根目录)
- 可选参数
--resource --controller --route --ignored-schema-regular= --force --all
~ 运行一个例子试试
php artisan swagger-to-code:gen ./vendor/kaxiluo/swagger-laravel-code-generator/example-swagger/example-openapi.yaml --ignored-schema-regular=^Error* --all
模型 && 资源
根据文档中的 schemas
生成对应的模型和资源类,默认不会生成User模型
可选参数:--ignored-schema-regular=
参数说明:忽略文档中模型的正则表达式,示例中 --ignored-schema-regular=^Error*
表示不生成以Error开头的模型和资源
举个栗子,如果swagger中定义有如下schema:
生成的模型:Article
Comment
Author
生成的资源:
app/Http/Resources/ArticleResource.php
app/Http/Resources/AuthorResource.php
app/Http/Resources/ArticleDetailResource.php
app/Http/Resources/CommentResource.php
控制器 && 路由
根据文档中 paths
定义的 operationId
生成对应的控制器和路由,如果没有定义operationId
将不会生成控制器和路由
举个栗子,如果swagger中定义
生成的控制器:
app/Controllers/Article/ArticleController.php
, 类中包含index
方法
生成的路由:
Route::get('/articles', 'Article\ArticleController@index');