Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lichunqiang/yii2-swagger
yii2 with swagger-php
https://github.com/lichunqiang/yii2-swagger
restful swagger-php yii yii2 yii2-swagger
Last synced: 25 days ago
JSON representation
yii2 with swagger-php
- Host: GitHub
- URL: https://github.com/lichunqiang/yii2-swagger
- Owner: lichunqiang
- License: mit
- Created: 2015-12-06T16:08:32.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-04-28T03:21:52.000Z (6 months ago)
- Last Synced: 2024-09-30T22:17:52.554Z (about 1 month ago)
- Topics: restful, swagger-php, yii, yii2, yii2-swagger
- Language: PHP
- Homepage: https://packagist.org/packages/light/yii2-swagger
- Size: 61.5 KB
- Stars: 151
- Watchers: 10
- Forks: 47
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-yii2 - lichunqiang/yii2-swagger - swagger-demo) (Extension 扩展)
README
Yii2 Swagger Extension
[![version](https://img.shields.io/packagist/v/light/yii2-swagger.svg?style=flat-square)](https://packagist.org/packages/light/yii2-swagger)
[![Download](https://img.shields.io/packagist/dt/light/yii2-swagger.svg?style=flat-square)](https://packagist.org/packages/light/yii2-swagger)
[![Issues](https://img.shields.io/github/issues/lichunqiang/yii2-swagger.svg?style=flat-square)](https://github.com/lichunqiang/yii2-swagger/issues)[swagger-php](https://github.com/zircote/swagger-php) integration with yii2.
Integration [swagger-ui](https://github.com/swagger-api/swagger-ui) with [swagger-php](https://github.com/zircote/swagger-php).
Installation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
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](https://github.com/lichunqiang/yii2-swagger-demo).__License
-------
![MIT](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)