apidoc生成API文档,Thinkphp6使用ThinkPHP-ApiDoc

官方文档:  https://hgthecode.github.io/thinkphp-apidoc/

完结撒花.❀❀❀❀❀❀

 

TP6版本

  • 安装
composer require hg/apidoc
  • 去官网下载前端页面

https://hgthecode.github.io/thinkphp-apidoc/guide/install/

下载完成后解压,将apidoc文件夹拷贝到你的项目 public 目录下

打开浏览器访问 http://你的域名/apidoc/ ,出现接口文档页面,表示安装成功。

  • 出现404错误

https://hgthecode.github.io/thinkphp-apidoc/use/help/404/

如果使用的nginx,通过rewrite方式代替php中的PATH_INFO,location块 / 通用匹配中加上

 

if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?s=$1 last; 
    break;
}

 

  • 出现500错误

https://hgthecode.github.io/thinkphp-apidoc/use/help/500/

控制器中use一下

use hg\apidoc\annotation as Apidoc;
use app\utils\Abc;

 目录app新建文件夹utils新建文件Abc.php

<?php
namespace app\utils;
use Doctrine\Common\Annotations\Annotation;

/**
 * 自定义参数解释文件
 * @package hg\apidoc\annotation
 * @Annotation
 * @Target({"METHOD","CLASS"})
 */
class Abc extends Annotation
{}

修改config文件夹下apidoc.php

//指定生成文档的控制器
    'controllers'        => [
        'app\\controller\\Index',
    ],
  • 基础注释

https://hgthecode.github.io/thinkphp-apidoc/use/notes/api/

方法加示例注释,其他方法注释语法要对

/**
     * @Apidoc\Title("基础的注释方法")
     * @Apidoc\Desc("最基础的接口注释写法")
     * @Apidoc\Url("/v1/baseDemo/base")
     * @Apidoc\Method("GET")
     * @Apidoc\Tag("测试 基础")
     * @Apidoc\Header("Authorization", require=true, desc="Token")
     * @Apidoc\Param("username", type="string",require=true, desc="用户名" )
     * @Apidoc\Param("password", type="string",require=true, desc="密码" )
     * @Apidoc\Param("phone", type="string",require=true, desc="手机号" )
     * @Apidoc\Param("sex", type="int",default="1",desc="性别" )
     * @Apidoc\Returned("id", type="int", desc="新增用户的id")
     */

访问http://你的域名/apidoc/  查看效果

posted @ 2021-08-10 10:31  变形金刚之猩猩将军  阅读(1175)  评论(0编辑  收藏  举报