Laravel中使用apiDoc生成接口文档

apiDoc官网:http://apidocjs.com/
此组件非composer扩展,是基于npm

根目录下创建配置文件

apidoc.json

{
    "name": "laravel-api-demo",
    "version": "1.0.0",
    "description": "LARAVEL API DEMO",
    "title": "laravel api demo",
    "url" : "http://localhost/apidoc/"
}

在测试控制器中添加

如:

/**
 * @api {post} /authorizations 创建一个token (create a token)
 * @apiDescription 创建一个token (create a token)
 * @apiGroup Auth
 * @apiPermission none
 * @apiParam {Email} email     邮箱
 * @apiParam {String} password  密码
 * @apiVersion 0.2.0
 * @apiSuccessExample {json} Success-Response:
 *     HTTP/1.1 201 Created
 *     {
 *         "data": {
 *             "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vbHVtZW4tYXBpLWRlbW8uZGV1L2FwaS9hdXRob3JpemF0aW9ucyIsImlhdCI6MTQ4Mzk3NTY5MywiZXhwIjoxNDg5MTU5NjkzLCJuYmYiOjE0ODM5NzU2OTMsImp0aSI6ImViNzAwZDM1MGIxNzM5Y2E5ZjhhNDk4NGMzODcxMWZjIiwic3ViIjo1M30.hdny6T031vVmyWlmnd2aUr4IVM9rm2Wchxg5RX_SDpM",
 *             "expired_at": "2017-03-10 15:28:13",
 *             "refresh_expired_at": "2017-01-23 15:28:13"
 *         }
 *     }
 * @apiErrorExample {json} Error-Response:
 *     HTTP/1.1 401
 *     {
 *       "error": "用户面密码错误"
 *     }
 */

执行生成命令(生成位置:public/apidoc

apidoc -i App/Http/Controllers/ -o public/apidoc/

两个参数分别为扫描控制器目录及生成的html文档目录

访问文档

http://服务器地址/apidoc

效果

QQ截图20180821144133.png

标签: 无

精彩评论
  1. 1 1

    1223

发表评论: