mindertech/swagger-lite

轻松将Swagger集成到Laravel中

1.0.0 2021-06-25 08:17 UTC

This package is auto-updated.

Last update: 2024-09-25 16:04:33 UTC


README

基于Swagger 3的Laravel 5 API文档生成器

swagger lite 只需在控制器方法中添加几行代码。

安装

使用以下命令使用composer安装此包:

composer require mindertech/swagger-lite

之后,将此包添加到config/app.php中的providers数组中

Pgroot\SwaggerLite\SwaggerLiteServiceProvider::class,

然后调用

php artisan vendor:publish

使用方法

如果你完成了上述所有步骤,那么/config/swagger-lite.php文件应该会为你生成。

<?php
return array(
    'api' => [
        'version' => '1.0',
        'title' => 'API',
        'description' => '',
        'base-path' => '/api'
    ],
    'doc-route' => 'docs',
    'api-docs-route' => 'api/docs',
    "generateAlways" => true,
    "default-swagger-version" => "2.0",
);

控制器和方法

<?php
/**
 * A description of the api
 *
 * @api tag
 * @package App\Http\Controllers
 */
class TestController extends Controller {

    /**
     * A description of the method
     *
     * This is a Description. A Summary and Description are separated by either
     *
     * @param string|path|required $id Description of the parameterName 
     * @param int|query $pid test Description of the parameterName 
     * @param string $type Description of the parameterName 
     * @return string Indicates the number of items
     */
    public function index(){
        return ['index'];
    }
} 

注意: : "@api"是必需的

你可以设置参数如何发送,有3种选项

  • formData
  • path
  • query - 这是默认选项

参数可以是必需的,也可以不是必需的。 默认: false

这就完成了。现在你可以在APP_URL/docs访问你的新文档。