light/yii2-swagger

swagger intergation with yii2

Maintainers

👁 light

Package info

github.com/lichunqiang/yii2-swagger

pkg:composer/light/yii2-swagger

Statistics

Installs: 848 998

Dependents: 5

Suggesters: 0

Stars: 153

Open Issues: 0

3.0.7 2026-01-19 03:15 UTC

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT fee322e62e84da362c8babec8ec001329652ffdd

  • lichunqiang <light-li.woop@hotmail.com>

restfulextensiondocumentswaggeryii2


README

👁 Image

Yii2 Swagger Extension


👁 version
👁 Download
👁 Issues

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 light/yii2-swagger "~3.0" --dev

or add

"light/yii2-swagger": "~3.0"

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' => 'light\swagger\SwaggerAction',
 'restUrl' => \yii\helpers\Url::to(['/site/api'], true),
 ],
 //The resultUrl action.
 'api' => [
 'class' => 'light\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',
 ],
 ];
}

For security, you can config api key for protection.

Caching

public function actions()
{
 return [
 // ...
 'api' => [
 // ...
 'cache' => 'cache',
 'cacheKey' => 'api-swagger-cache', // default is 'api-swagger-cache'
 ],
 ];
}

Clear cache

Access clear cache url YOUR_API_URL?clear-cache or YOUR_API_URL?api_key=YOUR_API_KEY&clear-cache

Example: curl 'http://localhost/v1/swagger/api?clear-cache'

you will see: Succeed clear swagger api cache.

Finally

If there also some confused, you can refer the Demo.

License

👁 MIT