15 Star 35 Fork 15

风情万种 / api-doc

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

#api-doc

使用方法

####1、安装扩展

composer require weiwei/api-doc

####2、配置参数

  • 5.0安装好扩展后在 application\extra\ 文件夹下会生成 doc.php 配置文件
  • 5.1安装好扩展后在 application\config\ 文件夹下会生成 doc.php 配置文件
  • 在controller参数中添加对应的类
    'controller' => [
        'app\\api\\controller\\Demo' //这个是控制器的命名空间+控制器名称
    ]

####3、在相关接口类中增加注释参数( group 参数将接口分组,可选)

  • 方法如下:返回参数支持数组及多维数组
<?php
namespace app\index\controller;
use think\Controller;

/**
 * @title 测试demo
 * @description 接口说明
 * @group 接口分组
 * @header name:key require:1 default: desc:秘钥(区别设置)
 * @param name:public type:int require:1 default:1 other: desc:公共参数(区别设置)
 */
class Demo extends Controller
{
    /**
     * @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]]);
    }

    /**
     * @title 登录接口
     * @description 接口说明
     * @author 开发者
     * @url /api/demo
     * @method GET
     * @module 用户模块

     * @param name:name type:int require:1 default:1 other: desc:用户名
     * @param name:pass type:int require:1 default:1 other: desc:密码
     *
     * @return name:名称
     * @return mobile:手机号
     *
     */
    public function login(Request $request)
    {
        //接口代码
        $device = $request->header('device');
        echo json_encode(["code"=>200, "message"=>"success", "data"=>['device'=>$device]]);
    }
}

####4、在浏览器访问http://你的域名/doc 或者 http://你的域名/index.php/doc 查看接口文档

####5、预览

###更多支持

  • QQ群663447446

###赞助二维码

###2017年8月16日更新

  • 增加头部参数设置,根据自己需求去设置参数
  • 增加全局参数设置及类参数设置,全局参数设置可以doc.php public_param、public_header配置,类局部公用参数可在class下面进行设置,详见demo.php
  • 增加模拟请求方式get、post、put、delete,注释课设置method参数进行标识

###问题

  • 不少小伙伴反应,没有正常安装doc.php 配置文件,原因是你改过应用目录官方默认是application
  • 如果没有生成doc.php 配置文件 你可以手动安装,直接在application(你修改的目录)里面创建extra文件夹,然后把扩展包中的vendor\weiwei\api-doc\src\config.php文件复制进去,并重命名为doc.php

###2018年6月1日更新

  • 增加TP5.1支持
  • 增加简单的访问验证(默认不开启密码,要开启只需在doc.php配置password值)
  • 增加静态资源自定义路径方式(可以把扩展下面的assets目录复制到你的pulic目录,然后配置static_path='/assets'),特么是nginx线上服务器可以这么做
  • 增加文档搜索功能
The MIT License (MIT) Copyright (c) 2017 风情万种 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

The ThinkPHP5 Api Doc Package 展开 收起
PHP
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/1763692101/api-doc.git
git@gitee.com:1763692101/api-doc.git
1763692101
api-doc
api-doc
master

搜索帮助