PHPackages                             shuyudao/p2api - 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. shuyudao/p2api

ActiveLibrary[API Development](/categories/api)

shuyudao/p2api
==============

API document generator based on controller method annotation

10PHP

Since Apr 9Pushed 6y ago1 watchersCompare

[ Source](https://github.com/shuyudao/P2API)[ Packagist](https://packagist.org/packages/shuyudao/p2api)[ RSS](/packages/shuyudao-p2api/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

P2API
=====

[](#p2api)

基于方法注释的API接口文档生成工具

快速通用、方便简单、基于同方法注释，在写注释的同时就把API文档给写完了。

同时你也可开发自定义接口文档模板、灵活添加注释字段满足更多个性化的需求，可搭配IDE的自动注释生成。

要求
--

[](#要求)

- PHP 5.6+

安装使用
----

[](#安装使用)

只要有注释，理论上都可以使用P2API，甚至不限于PHP语言。

将项目克隆到本地：

```
git clone https://github.com/shuyudao/P2API

```

然后进入项目，可以看到 `config.php` 文件，配置父级公共目录，这个公共目录，主要作用就是让你在class配置里少复制一段路径。

`class`，是注释API的文件，一般是框架的控制器文件，如果有多个，就配置多个。

同时需要注意的是，`publicPath+class['你的文件']` 拼接起的路径必须为完整路径

```
//配置实例
$config = array(
    "publicPath"=>"C:\Users\sad\Desktop\test\app\controller\", //公共目录，绝对路径，是下面class所有文件共同的父目录
    "class"=>[
        "StudentCtrl.php",
        "haha/IndexCtrl.php"
    ],//含有API接口注释的类文件
    "preface"=>["API接口项目名","项目描述，支持HTML"], //文档首页
    "outpath"=>"C:\Users\sad\Downloads\mydoc" //生成文档的保存位置，必须为目录，绝对路径
);

```

给你的控制器或者相关的PHP类方法上添加要求的注释

然后，在P2API项目根目录使用php命令执行，必须使用php命令执行该文件，也就是php-cli

```
php index.php

```

注释要求
----

[](#注释要求)

标准完整注释

```
    /**
     * @des 用户注册
     * @paths /user/reg
     * @method POST
     * @parameter ["user","是","string","用户名"],["password","是","string","密码"]
     * @returnParameter ["code","int","状态"]
     * @response {"code":200}
     * @tips 这是接口备注
    */
    public function FunctionName(){...}

```

其中 `@parameter`、`@returnParameter`、`@response`、`@tips`可以不需要，如果注释了，就一定要赋值，不要留空。

同时你也可以添加新的字段以`@xxx `的形式，在自己开发的模板中使用。

#### 注释释义

[](#注释释义)

- `@des` - 接口描述，如果值类似于`用户模块 注册`，则会自动分级显示，最多支持两级。`必填`✔
- `@paths` - 请求路径，接口的请求URL。`必填`✔
- `@method` - 请求方法，POST/GET/PUT... 其实都不限制你的值内容，写个SB都行。`必填`✔
- `@parameter` - 请求参数列表，一个参数信息包含在`[]`中，须有四个参数为：`参数名称`、`参数必选`、`参数类型`、`参数说明`，多个参数以半角逗号分割
- `@returnParameter` - 响应参数列表，四个参数为：`参数名称`、`参数类型`、`参数说明`，其它同上
- `@response` - 返回示例，正常的响应返回内容，json格式字符串，一行
- `@tips` - 接口备注

其中，`@response`、 `@tips`可以不写上去以外，其它的均建议写上，除非参数列表实在没有。

再次说明，可选参数注释要么不写上去，要么就不要留空。注释参数值，其实任何值都行，如果你使用自定义的模板，可以随你怎么填值，但是三个必填注释，必须有。

默认效果
----

[](#默认效果)

[![image.png](https://camo.githubusercontent.com/2293852a02331c89f39595b59426224d0546aedc1030ba5682c996de8196f95e/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f6734394148624757525a6b444f6c492e706e67)](https://camo.githubusercontent.com/2293852a02331c89f39595b59426224d0546aedc1030ba5682c996de8196f95e/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f6734394148624757525a6b444f6c492e706e67)

[![image.png](https://camo.githubusercontent.com/393108e13a74046cc56dd78899b69161da6ea6c8a8b97aac451bae6e6a7b8ed8/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f65714142535978334e3957547773502e706e67)](https://camo.githubusercontent.com/393108e13a74046cc56dd78899b69161da6ea6c8a8b97aac451bae6e6a7b8ed8/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f65714142535978334e3957547773502e706e67)

[![image.png](https://camo.githubusercontent.com/8d620b7090660fd4683fc8a17a2ed275ec07b4d3a235aee4d4e354b4e5cacadb/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f67484133666c46326f37364c5943582e706e67)](https://camo.githubusercontent.com/8d620b7090660fd4683fc8a17a2ed275ec07b4d3a235aee4d4e354b4e5cacadb/68747470733a2f2f692e6c6f6c692e6e65742f323032302f30342f31302f67484133666c46326f37364c5943582e706e67)

更多实现
----

[](#更多实现)

- 自定义模板支持
- 多种输出方式
- 模拟测试请求
- 更多自定义
- 文档管理

License
-------

[](#license)

[The MIT License (MIT)](https://github.com/shuyudao/P2API/blob/master/LICENSE)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31978102?v=4)[ShakesCoke](/maintainers/shuyudao)[@shuyudao](https://github.com/shuyudao)

---

Top Contributors

[![shuyudao](https://avatars.githubusercontent.com/u/31978102?v=4)](https://github.com/shuyudao "shuyudao (19 commits)")

---

Tags

apiapi-documentationphp

### Embed Badge

![Health badge](/badges/shuyudao-p2api/health.svg)

```
[![Health](https://phpackages.com/badges/shuyudao-p2api/health.svg)](https://phpackages.com/packages/shuyudao-p2api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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