swagger ui 3.0 与 yii2 集成

1.4 2019-08-10 04:03 UTC

This package is auto-updated.

Last update: 2024-09-10 15:51:31 UTC


README

Yii2 Swagger Ui 3.0 扩展


swagger-php 与 yii2 的集成。

集成swagger-uiswagger-php

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

composer require lengbin/yii2-swagger "*"

"lengbin/yii2-swagger": "*"

将以下内容添加到您的 composer.json 文件的 require 部分。

用法

配置以下两个动作

//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'),
            ],
        ],
    ];
}

扩展

您可以使用 Gii 快速生成 Swagger OpenAPI 2.0 扩展 yii-gii-swagger