美文网首页
thinkphp6 自动api文档

thinkphp6 自动api文档

作者: 微笑城ios | 来源:发表于2021-03-17 14:37 被阅读0次

thinkphp6 自动 api 文档, 简单好用

IMG_0698.png

weiwei 回来了 , 支持 tp6 了!!!!!

- 6.0执行 1.7开始只支持tp6
composer require weiwei/api-doc

终于weiwei回来了, 之前在 tp5 上非常好用的一款自动 api 文档, 具有上手简单, 配置清晰的特点;

安装步骤

  1. composer 安装一下
composer require weiwei/api-doc
  1. 将 /vendor/weiwei/api-doc/src/config/doc cp 到 config 目录下
cp /vendor/weiwei/api-doc/src/config/doc.php config
  1. 修改 config/doc.php
vim config/doc.php
### 配置一下这里 需要展示api 的controller  
'controller' => [
        //需要生成文档的类
        'app\admin\controller\Tools'
    ],
  1. 配置 控制器的头
/**
 * @title 测试保存题目信息
 * @description 用来保存题目的
 * @group admin
 * @header name:sessionKey require:1 default: desc:秘钥(区别设置)
 * @param name:public type:int require:1 default:1 other: desc:公共参数(区别设置)
 */
class Tools extends AdminBaseController
{

}
  1. 配置方法
/**
     * @title 测试demo接口
     * @description 接口说明
     * @author 开发者
     * @url /index/demo
     * @method GET
     *
     * @header name:device require:1 default: desc:设备号
     *
     * @param name:id type:int require:1 default:1 other: desc:唯一ID
     *
     * @return name:名称
     * @return mobile:手机号
     * @return list_messages:消息列表@
     * @list_messages message_id:消息ID content:消息内容
     * @return object:对象信息@!
     * @object attribute1:对象属性1 attribute2:对象属性2
     * @return array:数组值#
     * @return list_user:用户列表@
     * @list_user name:名称 mobile:手机号 list_follow:关注列表@
     * @list_follow user_id:用户id name:名称
     */
    public function index()
    {
        //接口代码
        $device = $this->request->header('device');
        echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
    }

  1. 运行tp
php think run
  1. 打开 http://localhost:8000/doc/index
    这里一定要注意 之前可以用doc 路径 , 现在不行了 ; 加上!! 加上 !! 没救了

weiwei 的资料网站

  1. https://github.com/zhangweiwei0326/api-doc/
  2. https://packagist.org/packages/weiwei/api-doc

加油 打工人

相关文章

网友评论

      本文标题:thinkphp6 自动api文档

      本文链接:https://www.haomeiwen.com/subject/zqfecltx.html