项目作者: lichunqiang

项目描述 :
yii2 with swagger-php
高级语言: PHP
项目地址: git://github.com/lichunqiang/yii2-swagger.git
创建时间: 2015-12-06T16:08:32Z
项目社区:https://github.com/lichunqiang/yii2-swagger

开源协议:MIT License

下载






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

  1. php composer.phar require --prefer-dist light/yii2-swagger "~3.0" --dev

or add

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

to the require section of your composer.json file.

Usage

Configure two action as below:

  1. public function actions()
  2. {
  3. return [
  4. //The document preview addesss:http://api.yourhost.com/site/doc
  5. 'doc' => [
  6. 'class' => 'light\swagger\SwaggerAction',
  7. 'restUrl' => \yii\helpers\Url::to(['/site/api'], true),
  8. ],
  9. //The resultUrl action.
  10. 'api' => [
  11. 'class' => 'light\swagger\SwaggerApiAction',
  12. //The scan directories, you should use real path there.
  13. 'scanDir' => [
  14. Yii::getAlias('@api/modules/v1/swagger'),
  15. Yii::getAlias('@api/modules/v1/controllers'),
  16. Yii::getAlias('@api/modules/v1/models'),
  17. Yii::getAlias('@api/models'),
  18. ],
  19. //The security key
  20. 'api_key' => 'balbalbal',
  21. ],
  22. ];
  23. }

For security, you can config api key for protection.

Caching

  1. public function actions()
  2. {
  3. return [
  4. // ...
  5. 'api' => [
  6. // ...
  7. 'cache' => 'cache',
  8. 'cacheKey' => 'api-swagger-cache', // default is 'api-swagger-cache'
  9. ],
  10. ];
  11. }

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