baitu/yii2-swagger

swagger intergation with yii2

1.0.4 2021-06-15 02:36 UTC

This package is auto-updated.

Last update: 2024-04-15 08:39:52 UTC


README

993323

Yii2 Swagger Extension


swagger-php integration with yii2.

Integration swagger-ui with swagger-php.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist baitu/yii2-swagger "*" --dev

or add

"baitu/yii2-swagger": "~1.0.4"

to the require section of your composer.json file.

Usage

Configure two action as below:

public function actions()
{
    return [
        //The document preview addesss:http://api.yourhost.com/site/doc
        'doc' => [
            'class' => 'baitu\swagger\SwaggerAction',
            'restUrl' => \yii\helpers\Url::to(['/site/api'], true),
        ],
        //The resultUrl action.
        'api' => [
            'class' => 'baitu\swagger\SwaggerApiAction',
            //The scan directories, you should use real path there.
            'scanDir' => [
                Yii::getAlias('@api/modules/v1/swagger'),
                Yii::getAlias('@api/modules/v1/controllers'),
                Yii::getAlias('@api/modules/v1/models'),
                Yii::getAlias('@api/models'),
            ],
            //The security key
            'api_key' => 'balbalbal',
        ],
    ];
}