PHPackages                             bobitluo/php-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. bobitluo/php-swagger

ActiveLibrary[API Development](/categories/api)

bobitluo/php-swagger
====================

A PHP document generator that supports swagger

v0.6(6y ago)17011MITPHP

Since Aug 15Pushed 4y ago2 watchersCompare

[ Source](https://github.com/bobitluo/php-swagger)[ Packagist](https://packagist.org/packages/bobitluo/php-swagger)[ RSS](/packages/bobitluo-php-swagger/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (3)Versions (8)Used By (1)

php-swagger
===========

[](#php-swagger)

Introduction
------------

[](#introduction)

一个基于 [phpDocumentor](https://www.phpdoc.org/) 生成 [Swagger2.0](https://swagger.io/docs/specification/2-0/basic-structure/) json 的PHP文档生成器

Installation
------------

[](#installation)

```
composer require bobitluo/php-swagger
```

Usage
-----

[](#usage)

```
$options = [
    'title' => 'API title',    // API系统标题
    'description' => 'API description',    // API系统描述
    'version' => '1.0.0',    // API版本号
    'host' => '{yourhost.com}',    // API系统域名
    'schemes' => [    // API支持的SCHEME列表
        'https',
    ],
    'securityDefinitions' => [    // API支持的认证列表。无需验证时设置为[]。详情见：https://swagger.io/docs/specification/2-0/authentication/
        'ApiKeyAuth' => [
            'type' => 'apiKey',
            'in' => 'header',
            'name' => 'Authorization',
        ],
    ],
    'security' => [    // API默认全局使用的认证定义。无需验证时设置为[]。详情见：https://swagger.io/docs/specification/2-0/authentication/
        [
            'ApiKeyAuth' => [],
        ],
    ],
    'controller_prefix' => '',    // 控制器类名前缀。默认值为''
    'controller_postfix' => '',    // 控制器类名后缀。默认值为''
    'action_prefix' => '',    // Action方法名前缀。默认值为空''
    'action_postfix' => '',    // Action方法名后缀。默认值为空''
];

\bobitluo\Php\Swagger\Options::getInstance( $options );
$directory = new \bobitluo\Php\Swagger\Directory('{your_controller_dir}', function($uriPath){
    return preg_replace('/(\/controllers)$/', '', $uriPath);
});
echo $directory->build();
```

PHP注释样例
-------

[](#php注释样例)

```
/**
 * @package 用户
 */
class UserController {

    /**
     * 登录
     *
     * 支持密码和验证码两种方式登录
     *
     * @package 用户
     * @http-method post
     *
     * @param string $login_type* 登录类型(password,sms_code) password
     * @param int $cellphone* 手机号 13800138000
     * @param string $password* 密码 123456
     * @param array $options[] 选项数组 10
     * @param array $ext[id][] 扩展ID数组
     * @param array $ext[name][] 扩展名称数组
     *
     * @return json 200 成功
     *
     * 字段解释:
     *
     * 名称    | 类型 | 示例 | 描述
     * ------- | ---- | ---- | ----
     * expires | int | 1565796956 | 凭证过期时间戳
     * type    | string | Bearer | 凭证类型
     * token   | string | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | 登录凭证
     *
     * 返回样例:
     *
     * ```
     * {
     *   "ret_code": 200,
     *   "ret_msg": "success",
     *   "result": {
     *     "expires": 1565796956,
     *     "type": "Bearer",
     *     "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
     *   }
     * }
     * ```
     * @return json 401 认证失败
     */
    public function loginAction() {
	  ...
```

PHP注释描述
-------

[](#php注释描述)

namedescriptionexamplecommenttitle接口标题登录建议简短descritpion接口描述支持密码和验证码两种方式登录可多行@package接口所在的分类@package 用户SwaggerUI中会根据分类分组显示。
可在Controller类注释中添加此类所有Action的默认分类@http-method接口请求方法@http-method post目前仅较好的支持get, post@param接口参数@param string $cellphone\* 手机号 13800138000数据类型 参数名($开头,末尾加\*表示必填) 参数描述 默认值@return接口返回@return json 200 成功

 字段解释:

 名称 | 类型 | 示例 | 描述
 ------ | ------ | ------ | -----
 expires | int | 1565796956 | 凭证过期时间戳
 ...@return 标签后紧跟接口返回类型(如：json, xml)，返回码，返回码描述。后续多行支持[Markdown](https://guides.github.com/features/mastering-markdown/)格式的内容

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~49 days

Recently: every ~61 days

Total

6

Last Release

2265d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7253963?v=4)[bobit](/maintainers/bobitluo)[@bobitluo](https://github.com/bobitluo)

---

Top Contributors

[![bobitluo](https://avatars.githubusercontent.com/u/7253963?v=4)](https://github.com/bobitluo "bobitluo (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/bobitluo-php-swagger/health.svg)

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

###  Alternatives

[phpdocumentor/phpdocumentor

Documentation Generator for PHP

4.3k3.1M903](/packages/phpdocumentor-phpdocumentor)[kimai/kimai

Kimai - Time Tracking

4.8k8.7k1](/packages/kimai-kimai)[m165437/laravel-blueprint-docs

API Blueprint Renderer for Laravel

22779.5k](/packages/m165437-laravel-blueprint-docs)[ezsystems/ezplatform-graphql

GraphQL server for the eZ Platform Open Source CMS Repository.

31655.7k12](/packages/ezsystems-ezplatform-graphql)[pronamic/wp-documentor

Documentation Generator for WordPress.

6531.7k7](/packages/pronamic-wp-documentor)[r2luna/brain

Brain: A process-driven architecture alternative for your Laravel Application.

6333.0k1](/packages/r2luna-brain)

PHPackages © 2026

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