PHP code example of cdyun / webman-swagger

1. Go to this page and download the library: Download cdyun/webman-swagger library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cdyun / webman-swagger example snippets




return [
    ...,
    // swagger配置
    'swagger' => [
        // swagger应用分组,支持插件和主应用,下面两个demo可删除
        'groups' => [
            [
                // 扫描指定应用目录,每个应用的OA\Info信息,必须且只能存在一个,所以建议写在每个应用控制器继承的 BaseController.php 上
                'scan_path' => base_path('app/v1'),
                // 分组标题,会替换掉OA\Info中的title
                'title' => 'v1应用接口文档',
                // 分组描述,会替换掉OA\Info中的description
                'description' => '让开发变得更简单、更通用、更流行。',
            ],
            [
                // 分组标题
                'title' => 'admin插件接口文档',
                // 分组描述
                'description' => '让开发变得更简单、更通用、更流行。',
                // 扫描指定应用目录,每个应用的OA\Info信息,必须且只能存在一个,所以建议写在每个应用控制器继承的 BaseController.php 上
                'scan_path' => base_path('plugin/admin'),
            ],
        ],
        // 是否登录功能
        'login' => [
            // 是否开启
            'enable' => true,
            // 登录验证接口, 为空时使用默认。支持内链(/v1/core/login)和外链(http://xxx.com/v1/core/login)
            'check_url' => '',
            // 登录验证接口为空时,默认登录用户名
            'username' => 'cdyun',
            // 登录验证接口为空时,默认登录密码
            'password' => 'swagger'
        ]
    ],
];


namespace app\v1\controller;

use support\base\BaseController;
use OpenApi\Attributes as OA;

#[OA\Info(version: '1.0.0', title: 'V1')]
class V1BaseController extends BaseController
{
    /**
     * @OA\Get(
     *     path="/index",
     *     @OA\Response(response="200", description="{ 'code': 0, 'msg': 'ok' }")
     * )
     */
	public function index(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }
    ...其他
}


namespace app\v2\controller;

use support\base\BaseController;
use OpenApi\Attributes as OA;

#[OA\Info(version: '2.0.0', title: 'V2')]
class V2BaseController extends BaseController
{
    ...其他
}