PHP code example of ziyoren / swagger

1. Go to this page and download the library: Download ziyoren/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/ */

    

ziyoren / swagger example snippets




namespace app\controller;

use support\Request;

/**
 * @OA\Info(
 *   title="我的第一个API",
 *   version="0.0.1",
 *   contact={
 *     "name": "技术支持",
 *     "email": "[email protected]"
 *   }
 * )
 */


class IndexController
{


    public $name;

    
    public function index(Request $request)
    {
        return response('hello webman'. $this->name);
    }

    public function view(Request $request)
    {
        return view('index/view', ['name' => 'webman']);
    }


    /**
     * @OA\Get(
     *     path="/index/json",
     *     @OA\Response(response="200", description="{ 'code': 0, 'msg': 'ok' }")
     * )
     */

    public function json(Request $request)
    {
        return json(['code' => 0, 'msg' => 'ok']);
    }

}




use support\Request;

return [
    'debug' => true,
    'controller_suffix' => 'Controller',
    'controller_reuse' => false,
    'version' => '0.1.0',
    //增加对model目录的扫描
    'scan_path' => [app_path('controller'), app_path('model')],
];