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 hgapidocannotation as Apidoc;
use apputilsAbc;

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

<?php
namespace apputils;
use DoctrineCommonAnnotationsAnnotation;

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

修改config文件夹下apidoc.php

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

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

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

/**
     * @ApidocTitle("基础的注释方法")
     * @ApidocDesc("最基础的接口注释写法")
     * @ApidocUrl("/v1/baseDemo/base")
     * @ApidocMethod("GET")
     * @ApidocTag("测试 基础")
     * @ApidocHeader("Authorization", require=true, desc="Token")
     * @ApidocParam("username", type="string",require=true, desc="用户名" )
     * @ApidocParam("password", type="string",require=true, desc="密码" )
     * @ApidocParam("phone", type="string",require=true, desc="手机号" )
     * @ApidocParam("sex", type="int",default="1",desc="性别" )
     * @ApidocReturned("id", type="int", desc="新增用户的id")
     */

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

原文地址:https://www.cnblogs.com/cnwp007/p/15122504.html