PHPackages                             widuu/think-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. [API Development](/categories/api)
4. /
5. widuu/think-api

ActiveLibrary[API Development](/categories/api)

widuu/think-api
===============

thinkphp6 api doc generation tool

0.0.2(4y ago)110Apache-2.0PHPPHP &gt;=7.1.0

Since Aug 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/widuu/think-api)[ Packagist](https://packagist.org/packages/widuu/think-api)[ RSS](/packages/widuu-think-api/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

think-api
=========

[](#think-api)

> Thinkphp 6 api 文档生成系统

### 安装

[](#安装)

```
composer require widuu/think-api

```

### 配置

[](#配置)

```
return [
    // api 名称,生成文档的头部显示文字
    'api_name'           => '测试API',
    // api 接口请求地址
    'api_url'            => '',
    // api 作者
    'api_author'         => '',
    // 默认语言，其它语言在 vendor/widuu/think-api/src/lang 下添加对应的语言
    'api_language'       => 'zh-cn',
    // 将哪个模块作为api使用，如果没有安装多应用模块，这个是 controller 名称
    'module_name'        => 'index',
    // api 路由，注册路由显示 api 文档
    'api_route'          => '/api',
    // api 路由绑定域名，显示文档的域名
    'api_route_domain'   => '',
    // api 自动生成地址的后缀
    'api_url_suffix'      => false,
    // api 排除类中的方法，譬如你有个 init 等等
    'api_method_fileter'  => [],
    // api 缓存名称，目录缓存，如果为空缓存，如果不为空就缓存
    'api_cache_name'     => 'THINK_APIDOC_CACHE',
    // 附加类库，将其它类库显示文档
    'extend_class'       => [

    ],
];

```

### 使用

[](#使用)

> 生成静态文档，使用 php think api 参数如下

```
  -u, --url[=URL]            default api url [default: ""]
  -m, --module[=MODULE]      module name like index [default: "index"]
  -o, --outfile[=OUTFILE]    output index file name [default: "api.html"]
  -f, --force[=FORCE]        force override general file [default: false]
  -t, --name[=NAME]          document api name [default: "测试API"]
  -c, --class[=CLASS]        extend class (multiple values allowed)
  -l, --language[=LANGUAGE]  language [default: "zh-cn"]

```

> 实时访问通过配置中定义的路由就可以直接访问了

### 注释说明

[](#注释说明)

#### 类注解

[](#类注解)

名称说明实例@ApiTitle类说明，如果不存在分组（@ApiSector）标题当成分组@ApiTitle("测试类")@ApiSector分组，如果类内部方法没有此注解，所有函数都归属于此分组@ApiSector("测试分组")@ApiInternal内部文档，禁止解析，使用之后此类不会被解析@ApiInternal(true)@ApiWeigh排序，数字越大，排序越靠上@ApiWeigh(10)#### 方法注解

[](#方法注解)

> 注只解析 `public` 方法，并且跳过 `__construct` 方法，如果想要跳过哪些方法，可以在 `config/api.php` 中的 `api_method_fileter` 中添加方法名称来跳过注解

名称说明实例@ApiInternal内部文档，禁止解析，使用之后此方法不会被解析@ApiInternal (true)@ApiTitle方法说明，如果不存在，会匹配注释的文档信息匹配中文和英文信息，不能有符号，匹配不成功就是英文名称@ApiTitle("测试方法")@ApiSector分组，如果不存在分组，则属于类内部分组@ApiSector ("测试分组")@ApiRoute路由，如果是指定的tinkphp的控制器，可以为空自动解析，但是如果其他类或者伪静态一定要指定，路由建议用""注释,防止解析{}符号@ApiRoute ("/index/test/{name}")@ApiMethodApi的请求方法，如果不存在就是 'GET' 方法@ApiMethod(POST)@ApiContentTypeApi 的 Content-type@ApiMethod ("multipart/form-data")@ApiHeaders请求头部信息，可以多个@ApiHeaders (name=username, type=string, required=true, description="请求的用户名")@ApiParams请求的参数，可以多个@ApiParams(name="name", type="string", required=true, description="方法名字")@ApiReturnParams返回参数说明，可以多个@ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回的状态")@ApiReturnHeaders返回头部，可以多个@ApiReturnHeaders (name="token", type="integer", required=true, sample="xxxxxxxx")@ApiReturn返回结果示例,json中使用"",因为会解析{}@ApiReturn ("{'code':1,'msg':'返回成功','data':{'test':1}}")@ApiBodybody正文@ApiBody ("body")@ApiWeigh排序，数字越大，排序越靠上@ApiWeigh(10)#### 示例

[](#示例)

```
