PHP code example of hyperf-plus / swagger

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

    

hyperf-plus / swagger example snippets


// config/autoload/swagger.php  swagger 基础信息

declare(strict_types=1);

return [
    'output_file' => BASE_PATH . '/runtime/swagger.json',
    'swagger' => '2.0',
    'enable' =>true, // 是否启用web访问
        // 忽略的hook, 非必须 用于忽略符合条件的接口, 将不会输出到上定义的文件中
     'ignore' => function($controller, $action) {
         return false;
     },
     // 自定义验证器错误码、错误描述字段
     'error_code' => 400,
     'http_status_code' => 400,
     'field_error_code' => 'code',
     'field_error_message' => 'message',
     // swagger 的基础配置
     'swagger' => [
         'swagger' => '2.0',
         'info' => [
             'description' => 'hyperf swagger api desc',
             'version' => '1.0.0',
             'title' => 'HYPERF API DOC',
         ],
         'host' => 'apidog.com',
         'schemes' => ['http'],
     ]
];

php bin/hyperf.php vendor:publish hyperf-plus/swagger

默开启文档web访问,如需关闭,在 config/autoload/swagger.php 将enable设为false