1 Star 2 Fork 0

Admin / real-apidoc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

基础介绍

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

引用

下载到tp6的extend\jmwl下

use  jmwl\realapidoc\Builder;
use  think\facade\View;

使用

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

            $title="类名";
        $url="http://real-think.jmwl51.com"; 
        //这里是所有的需要生成api的控制器路径啦
        $builder = new Builder(["\\app\\admin\\controller\\command"]);
        $content = $builder->render(root_path()."/extend/jmwl/realapidoc/template/index.html",$title,$url);
        // dump($content); die;
     
        View::assign('config',$content["config"]);
        View::assign('docslist',$content["docsList"]);
        View::assign('lang',$content["lang"]);
       return View();

视图

文件中的index.html就是视图啦,放到正确的位置 我放在了 app\admin\view\api\index.html 对应的控制器自然是 admin下的api控制器啦

控制器注释

名称 描述 示例
@ApiSector API分组名称 (测试分组)
@ApiRoute API接口URL,此@ApiRoute只是基础URL (/api/test)
@ApiInternal 忽略的控制器,表示此控制将不加入API文档
@ApiWeigh API方法的排序,值越大越靠前 (99)

控制器方法注释

名称 描述 示例
@ApiTitle API接口的标题,为空时将自动匹配注释的文本信息 (测试标题)
@ApiSummary API接口描述 (测试描述)
@ApiRoute API接口地址,为空时将自动计算请求地址 (/api/test/index)
@ApiMethod API接口请求方法,默认为GET (POST)
@ApiSector API分组,默认按钮控制器或控制器的@ApiSector进行分组 (测试分组)
@ApiParams API请求参数,如果在@ApiRoute中有对应的{@参数名},将进行替换 (name="id", type="integer", required=true, description="会员ID")
@ApiHeaders API请求传递的Headers信息 (name=token, type=string, required=true, description="请求的Token")
@ApiReturn API返回的结果示例 ({"code":1,"msg":"返回成功"})
@ApiReturnParams API返回的结果参数介绍 (name="code", type="integer", required=true, sample="0")
@ApiReturnHeaders API返回的Headers信息 (name="token", type="integer", required=true, sample="123456")
@ApiInternal 忽略的方法,表示此方法将不加入文档
@ApiWeigh API方法的排序,值越大越靠前 (99)

示范

<?php

namespace app\api\controller;

/**
 * 测试API控制器
 */
class Test extends \app\common\controller\Api
{

    // 无需验证登录的方法
    protected $noNeedLogin = ['test'];
    // 无需要判断权限规则的方法
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     * 可以通过@ApiInternal忽略请求的方法
     * @ApiInternal
     */
    public function index()
    {
        return 'index';
    }

    /**
     * 私有方法
     * 私有的方法将不会出现在文档列表
     */
    private function privatetest()
    {
        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':'返回成功'
     * })
     */
    public function test($id = '', $name = '')
    {
        $this->success("返回成功", $this->request->request());
    }

}
BSD 3-Clause License Copyright (c) 2021, Admin All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

real-apidoc 展开 收起
PHP 等 2 种语言
BSD-3-Clause
取消

发行版 (1)

全部
1.0

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/jinan-jimeng-network_0/real-apidoc.git
git@gitee.com:jinan-jimeng-network_0/real-apidoc.git
jinan-jimeng-network_0
real-apidoc
real-apidoc
master

搜索帮助