widuu / think-api
thinkphp6 api doc generation tool
0.0.2
2021-08-07 08:52 UTC
Requires
- php: >=7.1.0
- topthink/framework: ^6.0.0
This package is auto-updated.
Last update: 2025-01-07 16:58:32 UTC
README
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"]
实时访问通过配置中定义的路由就可以直接访问了
注释说明
类注解
方法注解
注只解析
public
方法,并且跳过__construct
方法,如果想要跳过哪些方法,可以在config/api.php
中的api_method_fileter
中添加方法名称来跳过注解
示例
<?php
namespace app\index\controller\test;
/**
* @ApiTitle("测试API")
* @ApiWeigh (20)
* Class Index
* @package app\index\controller\test
*/
class Index
{
/**
* 测试方法
*
* @ApiTitle (测试名称)
* @ApiSector (测试分组)
* @ApiDescription (测试描述信息)
* @ApiRoute ("/index/index.test/index/{name}")
* @ApiContentType ("multipart/form-data")
* @ApiMethod (POST)
* @ApiHeaders (name=username, type=string, required=true, description="请求的用户名")
* @ApiBody (测试正文)
* @ApiParams (name="name", type="string", required=true, description="用户名")
* @ApiReturnParams (name="code", type="integer", required=true, sample="0", description="返回的状态")
* @ApiReturnHeaders (name="token", type="integer", required=true, sample="xxxxxxxx")
* @ApiReturn ("{
* 'code':'1',
* 'mesg':'返回成功'
* }")
*/
public function index()
{}
/**
* 方法测试
*/
public function test()
{}
/**
* 跳过注解的方法
* @ApiInternal(true)
*/
public function say()
{}
}