real-apidoc 基于 tp6 的 api 生成模块开源项目

我要开发同款
匿名用户2021年12月21日
24阅读
开发技术PHP
所属分类Web应用开发、网站API
授权协议BSD

作品详情

基于tp6的api生成模块,参考fastadmin的api模块

引用下载到tp6的extend\jmwl下

usejmwl\realapidoc\Builder;usethink\facade\View;使用这里是所有的需要生成api的控制器路径啦、所以,你可以先获取到模块下的所有控制器Builder(["\app\admin\controller\Demo","\app\admin\controller\Index"])

$title="类名";$url="https://real-think.jmwl51.com";$lang=['Info'=>'基础信息','Sandbox'=>'在线测试','Sampleoutput'=>'返回示例','Headers'=>'Headers','Parameters'=>'参数','Body'=>'正文','Name'=>'名称','Type'=>'类型','Required'=>'必选','Description'=>'描述','Send'=>'提交','Reset'=>'重置','Tokentips'=>'Token在会员注册或登录后都会返回,WEB端同时存在于Cookie中','Apiurltips'=>'API接口URL','Savetips'=>'点击保存后Token和Apiurl都将保存在本地Localstorage中','Authorization'=>'权限','NeedLogin'=>'登录','NeedRight'=>'鉴权','ReturnHeaders'=>'响应头','ReturnParameters'=>'返回参数','Response'=>'响应输出',];$config=['sitename'=>"测试",'title'=>$title,'author'=>"测试",'description'=>'','apiurl'=>$url,'language'=>$lang,];//这里是所有的需要生成api的控制器路径啦$builder=newBuilder(["\\app\\admin\\controller\\Demo","\\app\\admin\\controller\\Index"]);$content=$builder->render(root_path()."/extend/jmwl/realapidoc/template/index.html",['config'=>$config,'lang'=>$lang]);//dump($content);die;View::assign('config',$config);View::assign('docslist',$content["docsList"]);View::assign('lang',$content["lang"]);returnView();视图文件中的index.html就是视图啦,放到正确的位置我放在了app\admin\view\api\index.html对应的控制器自然是admin下的api控制器啦

控制器注释名称描述示例@ApiSectorAPI分组名称(测试分组)@ApiRouteAPI接口URL,此@ApiRoute只是基础URL(/api/test)@ApiInternal忽略的控制器,表示此控制将不加入API文档无@ApiWeighAPI方法的排序,值越大越靠前(99)控制器方法注释名称描述示例@ApiTitleAPI接口的标题,为空时将自动匹配注释的文本信息(测试标题)@ApiSummaryAPI接口描述(测试描述)@ApiRouteAPI接口地址,为空时将自动计算请求地址(/api/test/index)@ApiMethodAPI接口请求方法,默认为GET(POST)@ApiSectorAPI分组,默认按钮控制器或控制器的@ApiSector进行分组(测试分组)@ApiParamsAPI请求参数,如果在@ApiRoute中有对应的{@参数名},将进行替换(name="id",type="integer",required=true,description="会员ID")@ApiHeadersAPI请求传递的Headers信息(name=token,type=string,required=true,description="请求的Token")@ApiReturnAPI返回的结果示例({"code":1,"msg":"返回成功"})@ApiReturnParamsAPI返回的结果参数介绍(name="code",type="integer",required=true,sample="0")@ApiReturnHeadersAPI返回的Headers信息(name="token",type="integer",required=true,sample="123456")@ApiInternal忽略的方法,表示此方法将不加入文档无@ApiWeighAPI方法的排序,值越大越靠前(99)示范<?phpnamespaceapp\api\controller;/***测试API控制器*/classTestextends\app\common\controller\Api{//无需验证登录的方法protected$noNeedLogin=['test'];//无需要判断权限规则的方法protected$noNeedRight=['*'];/***首页**可以通过@ApiInternal忽略请求的方法*@ApiInternal*/publicfunctionindex(){return'index';}/***私有方法*私有的方法将不会出现在文档列表*/privatefunctionprivatetest(){return'private';}/***测试方法**@ApiTitle(测试名称)*@ApiSummary(测试描述信息)*@ApiSector(测试分组)*@ApiMethod(POST)*@ApiRoute(/api/test/test/id/{id}/name/{name})*@ApiHeaders(name=token,type=string,required=true,description="请求的Token")*@ApiParams(name="id",type="integer",required=true,description="会员ID")*@ApiParams(name="name",type="string",required=true,description="用户名")*@ApiParams(name="data",type="object",sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}",description="扩展数据")*@ApiReturnParams(name="code",type="integer",required=true,sample="0")*@ApiReturnParams(name="msg",type="string",required=true,sample="返回成功")*@ApiReturnParams(name="data",type="object",sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}",description="扩展数据返回")*@ApiReturn({'code':'1','mesg':'返回成功'*})*/publicfunctiontest($id='',$name=''){$this->success("返回成功",$this->request->request());}}
查看全文
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论