PHPackages                             light/yii2-swagger - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. light/yii2-swagger

ActiveLibrary[API Development](/categories/api)

light/yii2-swagger
==================

swagger intergation with yii2

3.0.7(4mo ago)154801.6k—8.4%474MITPHPCI failing

Since Dec 7Pushed 4mo ago10 watchersCompare

[ Source](https://github.com/lichunqiang/yii2-swagger)[ Packagist](https://packagist.org/packages/light/yii2-swagger)[ RSS](/packages/light-yii2-swagger/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (24)Used By (4)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 Swagger Extension
======================

[](#yii2-swagger-extension)

[![version](https://camo.githubusercontent.com/bf25dc76f66fa29fc77444e12e4b24626f82d4109df1769bac113e0c371bb50f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c696768742f796969322d737761676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/light/yii2-swagger)[![Download](https://camo.githubusercontent.com/df66d9a6b7ee581c7f3d3557e2c982acdb81b7166578a63117d26e14db4d2e31/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c696768742f796969322d737761676765722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/light/yii2-swagger)[![Issues](https://camo.githubusercontent.com/7445cb5a51e1ddcb92156a91366305fb3e7c7834b8ef610649b42151b65eaf8e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c696368756e7169616e672f796969322d737761676765722e7376673f7374796c653d666c61742d737175617265)](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
------------

[](#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
-----

[](#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
-------

[](#caching)

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

```

#### Clear 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
-------

[](#finally)

**If there also some confused, you can refer the [Demo](https://github.com/lichunqiang/yii2-swagger-demo).**

License
-------

[](#license)

[![MIT](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)

###  Health Score

63

—

FairBetter than 99% of packages

Maintenance78

Regular maintenance activity

Popularity56

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 55.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~168 days

Recently: every ~337 days

Total

23

Last Release

120d ago

Major Versions

0.2.3 → 1.0.02016-01-10

1.0.x-dev → 2.0.0-alpha2018-03-30

2.0.0-alpha → 3.0.02019-11-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ead2ef2c9862aa3d75a97de86af1e3cfa919886e8981bf0808cddd93f563777?d=identicon)[light](/maintainers/light)

---

Top Contributors

[![lichunqiang](https://avatars.githubusercontent.com/u/2433916?v=4)](https://github.com/lichunqiang "lichunqiang (33 commits)")[![Sensetivity](https://avatars.githubusercontent.com/u/4289543?v=4)](https://github.com/Sensetivity "Sensetivity (10 commits)")[![Krakozaber](https://avatars.githubusercontent.com/u/2918147?v=4)](https://github.com/Krakozaber "Krakozaber (5 commits)")[![dcb9](https://avatars.githubusercontent.com/u/3984347?v=4)](https://github.com/dcb9 "dcb9 (3 commits)")[![fhernandezn](https://avatars.githubusercontent.com/u/12898908?v=4)](https://github.com/fhernandezn "fhernandezn (1 commits)")[![Kolyunya](https://avatars.githubusercontent.com/u/2682768?v=4)](https://github.com/Kolyunya "Kolyunya (1 commits)")[![laxity7](https://avatars.githubusercontent.com/u/6792144?v=4)](https://github.com/laxity7 "laxity7 (1 commits)")[![aksafan](https://avatars.githubusercontent.com/u/14964793?v=4)](https://github.com/aksafan "aksafan (1 commits)")[![theblindfrog](https://avatars.githubusercontent.com/u/1281630?v=4)](https://github.com/theblindfrog "theblindfrog (1 commits)")[![clh021](https://avatars.githubusercontent.com/u/1754391?v=4)](https://github.com/clh021 "clh021 (1 commits)")[![ddanielroche](https://avatars.githubusercontent.com/u/10426548?v=4)](https://github.com/ddanielroche "ddanielroche (1 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

restfulswagger-phpyiiyii2yii2-swaggerswaggeryii2extensionrestfuldocument

### Embed Badge

![Health badge](/badges/light-yii2-swagger/health.svg)

```
[![Health](https://phpackages.com/badges/light-yii2-swagger/health.svg)](https://phpackages.com/packages/light-yii2-swagger)
```

###  Alternatives

[ignatenkovnikita/yii2-swagger

Swagger UI v3 intergation with yii2

128.0k](/packages/ignatenkovnikita-yii2-swagger)[conquer/services

Yii2 soap wsdl web services

1632.5k](/packages/conquer-services)[apexwire/yii2-restclient

Tools to use API as ActiveRecord for Yii2

143.5k](/packages/apexwire-yii2-restclient)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
