PHPackages                             ayang/api - 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. [CLI &amp; Console](/categories/cli)
4. /
5. ayang/api

ActiveLibrary[CLI &amp; Console](/categories/cli)

ayang/api
=========

一个简单的使用注解生成api文档的库

v1.0.2(1y ago)214MITPHPPHP ^8.0

Since Jul 29Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ayang9999/api)[ Packagist](https://packagist.org/packages/ayang/api)[ RSS](/packages/ayang-api/feed)WikiDiscussions main Synced today

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

PHP Api Document
================

[](#php-api-document)

![Php Version](https://camo.githubusercontent.com/3fe2b00a3b57acdbf9c6ee0890609712713224e8b654eff0d23e4a0ae3969828/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d382e302d627269676874677265656e2e7376673f6d61784167653d32353932303030)[![English](https://camo.githubusercontent.com/ed07c6ca77f8bef98ffb34dc57b13a2fe696ef80ad89c0630268726a72c12b26/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f526561646d652d456e676c6973682d627269676874677265656e2e7376673f6d61784167653d32353932303030)](README.en.md)

一个简单的使用注解生成接口文档的命令行工具类

预览效果
----

[](#预览效果)

[![默认md效果预览](./docs/images/docMd.png)](./docs/images/docMd.png)

[api document](./docs/apis)
---------------------------

[](#api-document)

功能概览
----

[](#功能概览)

- 根据注解生成接口 md格式文档，可以用 mdBook 生成html，也可以自行扩展
- 可以设置guzzle/http 客户端 ，根据注解请求接口，返回结果整合到文档中

项目地址
----

[](#项目地址)

- **github**
- **gitee**

快速安装
----

[](#快速安装)

- Requirement PHP 8.0+

```
composer require ayang/api
```

快速开始
----

[](#快速开始)

- 注解编写

```
use Ayang\ApiManager\Attr\api;
use Ayang\ApiManager\Attr\param;
use Ayang\ApiManager\Attr\request;
use Ayang\ApiManager\Attr\response;
use Ayang\ApiManager\Attr\respField;

class userController
{
    #[api(name:"获取用户信息", path: "/getInfo", method: "get", desc: "返回参考保存用户信息字段", category: "用户信息")]
    #[param("id", "int", '用户id', true)]
    #[respField("real_status", "bool", "实名认证 0未提交1审核中2通过3拒绝")]
    #[respField("education_status", "bool", "学历认证 0未提交1审核中2通过3拒绝")]
    #[respField("work_status", "bool", "company认证 0未提交1审核中2通过3拒绝")]
    #[respField("activity", "string", "活跃度")]
    #[respField("is_reg", "bool", "是否注册")]
    #[request(['id' => 1], right: false)]
    #[response('{"name":"小明"}')]
    public function getInfo()
    {
    }
}
```

- 生成文档

```
$dir = "/tmp/aYangDocTest"; //文档目录
$cateFile = "/tmp/aYangDocTest/cate.md"; //文档导航

$apiList = \Ayang\ApiManager\apiEntity::getByClass(\Ayang\ApiManager\Test\example\userController::class);
$maker = new \Ayang\ApiManager\Doc\documentMaker($apiList, new \Ayang\ApiManager\Display\Format\markdownFormat(), $dir, $cateFile);
$display = new \Ayang\ApiManager\display($maker);

$display->listApi();//列出全部 api

$maker->makeAll(); //生成文档
$maker->makeOne("GET", "/getInfo"); //生成或者覆盖指定单个接口
$maker->makeCategoryFile();// 生成导航文件

$display->printLog();//显示文档变化的接口
```

[![](./docs/images/new.png)](./docs/images/new.png)

- 注解修改

```
class userController
{
    #[api(name:"获取用户信息", path: "/getInfo", method: "get", desc: "返回参考保存用户信息字段", category: "用户信息")]
    #[param("userId", "int", '用户id', true)]
    #[respField("real_status", "bool", "实名认证 0未提交1审核中2通过3拒绝")]
    #[request(['userId' => 1], right: false)]
    #[response('{"name":"小明"}')]
    public function getInfo()
    {
    }
}

$maker2 = new \Ayang\ApiManager\Doc\documentMaker($apiList, new \Ayang\ApiManager\Display\Format\markdownFormat(), $dir, $cateFile);

$maker2->showChange();
$display = new \Ayang\ApiManager\display($maker2);
$display->printLog();//检查注解变化的接口
```

[![](./docs/images/check.png)](./docs/images/check.png)

- 根据注解发起http请求

```
//$resp = new GuzzleHttp\Psr7\Response(200,[],'{"code":0}');
//$guzzleClient = Mockery::mock(GuzzleHttp\Client::class);
//$guzzleClient->allows([
//    "request" => $resp//new GuzzleHttp\Psr7\Response(200,[],'{"code":0}')
//]);
// 根据注解 request 进行请求

$guzzleClient = new GuzzleHttp\Client();
$apiClient = new \Ayang\ApiManager\apiClient($guzzleClient);
$maker->setApiClient($apiClient);
$maker->makeAll();//or $maker->makeOne("GET", "/getInfo");
$display = new \Ayang\ApiManager\display($maker);
$display->printLog();//文档变化的接口
```

依赖包
---

[](#依赖包)

- [inhere/console](https://github.com/inhere/php-console)
- [guzzlehttp/guzzle](https://github.com/guzzle/guzzle/)
- sebastian/diff

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

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 ~1 days

Total

2

Last Release

702d ago

### Community

Maintainers

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

---

Top Contributors

[![ayang9999](https://avatars.githubusercontent.com/u/176839539?v=4)](https://github.com/ayang9999 "ayang9999 (16 commits)")

---

Tags

annotationapidocdocumentmarkdownphpphpcomposerapiclidocmarkdowndocumentannotation

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/ayang-api/health.svg)

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

###  Alternatives

[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)[pantheon-systems/terminus

A command line interface for Pantheon

3391.5M18](/packages/pantheon-systems-terminus)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M43](/packages/dereuromark-cakephp-ide-helper)[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

10097.5k](/packages/mehrancodes-laravel-harbor)[files.com/files-php-sdk

Files.com PHP SDK

2481.1k](/packages/filescom-files-php-sdk)[renoki-co/php-helm

PHP Helm Processor is a process wrapper for Kubernetes' Helm v3 CLI. You can run programmatically Helm v3 commands, directly from PHP, with a simple syntax.

1310.6k](/packages/renoki-co-php-helm)

PHPackages © 2026

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