PHPackages                             haohetao/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. haohetao/yii2-swagger

ActiveLibrary[API Development](/categories/api)

haohetao/yii2-swagger
=====================

swagger intergation with yii2

2.1.0(6y ago)03.7k↓100%MITPHP

Since Dec 7Pushed 5y agoCompare

[ Source](https://github.com/haohetao/yii2-swagger)[ Packagist](https://packagist.org/packages/haohetao/yii2-swagger)[ RSS](/packages/haohetao-yii2-swagger/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (19)Used By (0)

 [ ![](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) intergation 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 haohetao/yii2-swagger "dev-master" --dev

```

or add

```
"haohetao/yii2-swagger": "dev-master"

```

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

34

—

LowBetter than 78% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 54.2% 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 ~75 days

Recently: every ~123 days

Total

18

Last Release

2475d ago

Major Versions

0.2.3 → 1.0.02016-01-10

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

### Community

Maintainers

![](https://www.gravatar.com/avatar/49ee9003109866ee01a052ac1c956a4302217912349bac7c43c297647b3694f3?d=identicon)[haohetao](/maintainers/haohetao)

---

Top Contributors

[![lichunqiang](https://avatars.githubusercontent.com/u/2433916?v=4)](https://github.com/lichunqiang "lichunqiang (32 commits)")[![haohetao](https://avatars.githubusercontent.com/u/4592571?v=4)](https://github.com/haohetao "haohetao (12 commits)")[![Sensetivity](https://avatars.githubusercontent.com/u/4289543?v=4)](https://github.com/Sensetivity "Sensetivity (10 commits)")[![dcb9](https://avatars.githubusercontent.com/u/3984347?v=4)](https://github.com/dcb9 "dcb9 (3 commits)")[![clh021](https://avatars.githubusercontent.com/u/1754391?v=4)](https://github.com/clh021 "clh021 (1 commits)")[![Kolyunya](https://avatars.githubusercontent.com/u/2682768?v=4)](https://github.com/Kolyunya "Kolyunya (1 commits)")

---

Tags

swaggeryii2extensionrestfuldocument

### Embed Badge

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

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

###  Alternatives

[light/yii2-swagger

swagger intergation with yii2

154784.5k4](/packages/light-yii2-swagger)[ignatenkovnikita/yii2-swagger

Swagger UI v3 intergation with yii2

128.0k](/packages/ignatenkovnikita-yii2-swagger)[dotzero/yii2-amocrm

Расширение для Yii Framework 2 реализующее клиент для работы с API amoCRM

1639.4k](/packages/dotzero-yii2-amocrm)[conquer/services

Yii2 soap wsdl web services

1631.9k](/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)
