ice 2019-06-18 16:54:51 1043次浏览 0条评论 0 1 0

993323

Yii2 generate swagger annotation


This extension provides a Web-based code generator, called Gii, for Yii framework 2.0 applications. You can use Gii to quickly generate swagger 2.0(openapi 2.0) annotation.

For license information check the LICENSE-file.

Installation

The preferred way to install this extension is through composer.

Either run

composer require lengbin/yii-gii-swagger

or add

"lengbin/yii-gii-swagger": *

to the require-dev section of your composer.json file.

Usage

Once the extension is installed, simply modify your application configuration at your application\config\main_local.php as follows:

$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
    'class'      => 'yii\gii\Module',
    'generators' => [
        'swagger' => [
            'class'      => 'lengbin\gii\swagger\Generator', //class
            'parameters' => [                                //set default request parameters
                'parameterName'        => ['X-Api-Token'],
                'parameterDescription' => ['token'],
                'parameterIn'          => ['header'],
                'parameterType'        => ['string'],
                'parameterRequired'    => ['true'],
            ],
            'responses'  => [                               //set default respons parameters
                'responseStatus'      => [200, 'default'],
                'responseDescription' => ['success', '请求失败, http status 强行转为200, 通过code判断'],
                'ref'                 => ['SuccessDefault', 'ErrorDefault'],
            ],
        ],
        //...
    ],
];
//...

You can then access Gii through the following URL:

http://localhost/path/to/index.php?r=gii

or if you have enabled pretty URLs, you may use the following URL:

http://localhost/path/to/index.php/gii

extension

You can use swagger doc extension yii-swagger.

觉得很赞
亿速云
    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册