lengbin/yii-swagger

swagger ui 3.0 intergation with yii2

1.4 2019-08-10 04:03 UTC

This package is auto-updated.

Last update: 2024-04-10 14:45:28 UTC


README

993323

Yii2 Swagger Ui 3.0 Extension


swagger-php intergation with yii2.

Integration swagger-ui with swagger-php.

Installation

The preferred way to install this extension is through composer.

Either run

composer require lengbin/yii2-swagger "*"

or add

"lengbin/yii2-swagger": "*"

to the require section of your composer.json file.

Usage

Configure two action as below:

//The scan directories, you should use real path there.
DocController.php

public function actions()
{
    return [
        'doc' => [
            'class' => 'lengbin\swagger\SwaggerAction',
            'url' => \yii\helpers\Url::to(['/doc/api'], true),
            // support swagger ui 2 and  3
            'version' => \lengbin\swagger\SwaggerAction::SWAGGER_VERSION_DEFAULT,
            //if more url
            'urls' => [
                \yii\helpers\Url::to(['/doc/api'], true),
                ['name' => 'api', 'url' => '\yii\helpers\Url::to(['/doc/api2'], true)'],
            ],
            //'httpAuth' => ['account' => 'password'], // http auth
        ],
        'api' => [
            'class' => 'light\swagger\SwaggerApiAction',
            'scanDir' => [
                Yii::getAlias('@api/swagger'),
                Yii::getAlias('@api/modules/v1/controllers'),
            ],
        ],
    ];
}

extension

You can use Gii to quickly generate swaager openapi 2.0 extension yii-gii-swagger.