swagger-php intergation with yii2.
Integration swagger-ui with swagger-php.
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.
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'),
],
],
];
}
You can use Gii to quickly generate swaager openapi 2.0 extension yii-gii-swagger.