app/Http/Controllers/Api/apidoc.md
apiDoc 使用内联注释为 RESTful API 自动生成文档。 以下为所有官方支持的参数与其说明。
定义 API 方法的基本信息
@api {method} path title
GET、POST、PUT、DELETE 等/user/:id📘 示例:
@api {get} /user/:id Get user info
定义请求体参数
@apiBody [{type}] [field=defaultValue] [description]
{type} 参数类型(如 String, Number, Object, String[])[field] 可选字段(方括号表示可选)=defaultValue 默认值description 参数说明📘 示例:
@apiBody {String} lastname Mandatory Lastname.
@apiBody {Object} [address] Optional address object.
@apiBody {String} [address[city]] Optional city.
定义可复用的文档块
@apiDefine name [title] [description]
name:唯一标识title:简短标题description:多行描述📘 示例:
@apiDefine MyError
@apiError UserNotFound The <code>id</code> of the User was not found.
标记接口为弃用状态
@apiDeprecated [text]
text:提示文本,可带链接到新方法📘 示例:
@apiDeprecated use now (#User:GetDetails)
描述接口详细说明
@apiDescription text
📘 示例:
@apiDescription This is the Description.
It is multiline capable.
定义错误返回参数
@apiError [(group)] [{type}] field [description]
📘 示例:
@apiError UserNotFound The id of the User was not found.
定义错误返回示例
@apiErrorExample [{type}] [title]
example
📘 示例:
@apiErrorExample {json} Error-Response:
HTTP/1.1 404 Not Found
{ "error": "UserNotFound" }
定义接口使用示例
@apiExample [{type}] title
example
📘 示例:
@apiExample {curl} Example usage:
curl -i http://localhost/user/4711
定义所属分组
@apiGroup name
📘 示例:
@apiGroup User
定义请求头参数
@apiHeader [(group)] [{type}] [field=defaultValue] [description]
📘 示例:
@apiHeader {String} access-key Users unique access-key.
定义请求头示例
@apiHeaderExample [{type}] [title]
example
📘 示例:
@apiHeaderExample {json} Header-Example:
{
"Accept-Encoding": "gzip, deflate"
}
忽略当前文档块
@apiIgnore [hint]
📘 示例:
@apiIgnore Not finished method
定义接口唯一名称
@apiName name
📘 示例:
@apiName GetUser
定义请求参数
@apiParam [(group)] [{type}] [field=defaultValue] [description]
📘 示例:
@apiParam {Number} id Users unique ID.
@apiParam {String} [firstname] Optional firstname.
@apiParam {String} country="DE" Mandatory with default.
定义参数请求示例
@apiParamExample [{type}] [title]
example
📘 示例:
@apiParamExample {json} Request-Example:
{ "id": 4711 }
定义权限要求
@apiPermission name
📘 示例:
@apiPermission admin
标记接口为私有(可过滤)
@apiPrivate
定义查询参数(?query)
@apiQuery [{type}] [field=defaultValue] [description]
📘 示例:
@apiQuery {Number} id Users unique ID.
@apiQuery {String} [sort="asc"] Sort order.
定义接口测试请求 URL
@apiSampleRequest url
📘 示例:
@apiSampleRequest http://test.github.com/some_path/
定义成功返回参数
@apiSuccess [(group)] [{type}] field [description]
📘 示例:
@apiSuccess {String} firstname Firstname of the User.
@apiSuccess {String} lastname Lastname of the User.
定义成功返回示例
@apiSuccessExample [{type}] [title]
example
📘 示例:
@apiSuccessExample {json} Success-Response:
HTTP/1.1 200 OK
{ "firstname": "John", "lastname": "Doe" }
引用定义块(@apiDefine)
@apiUse name
📘 示例:
@apiDefine MySuccess
@apiSuccess {String} firstname User firstname.
@apiUse MySuccess
定义接口版本
@apiVersion version
📘 示例:
@apiVersion 1.6.2
| 标签 | 作用 | 示例 |
|---|---|---|
@api | 定义接口 | @api {get} /user/:id |
@apiName | 唯一名称 | @apiName GetUser |
@apiGroup | 所属分组 | @apiGroup User |
@apiParam | 请求参数 | @apiParam {Number} id Users unique ID. |
@apiBody | 请求体参数 | @apiBody {String} name Username. |
@apiQuery | 查询参数 | @apiQuery {String} keyword Search term. |
@apiHeader | Header 参数 | @apiHeader {String} token Auth token. |
@apiSuccess | 成功返回字段 | @apiSuccess {String} name Username. |
@apiError | 错误返回字段 | @apiError NotFound User not found. |
@apiVersion | 版本号 | @apiVersion 1.0.0 |