Skip to content

Instantly share code, notes, and snippets.

@LUN7
Last active December 27, 2020 03:49
Show Gist options
  • Save LUN7/96bd49c49380f66a7efd5f7658d7ccae to your computer and use it in GitHub Desktop.
Save LUN7/96bd49c49380f66a7efd5f7658d7ccae to your computer and use it in GitHub Desktop.
apidoc demo
/**
* @apiDefine admin admin title
* Only admin has permission to delete user <-- description
* apiDefine定義一個叫admin的block
* 可以再其他的註譯呼叫這個block
*/
/**
* @api {get} /user/:userId get user
* {method} {route} {desciption}
* 定義api的基本資料(必填)
*
* @apiName getUser
* End point的名稱 (必填)
*
* @apiGroup user
* End point 所屬於的群組
*
* @apiParam {String} userId User unique ID
* End point 的Param
*
* @apiSuccess {String} data "success"
* End point 的Success response
*
*/
module.exports.get = (req,res,next) => {
...
}
/**
* @api {delete} /user/:userId delete user
* @apiName deleteUser
* @apiGroup user
* @apiPermission admin
* 這裏要注意一下
* 我們可以用apiPermission來定義一下誰可以acess這個end point
* 因為先前apiDefine了admin所以生成出來的documentation也會reference去定義了的admin
* @apiParam {String} userId User unique ID
*
* @apiSuccess {String} data "success"
*
*/
module.exports.delete = (req,res,next) => {
...
}
/**
* @api {post} /user/:userId Edit user
* @apiName editUser
* @apiGroup user
*
* @apiParam {String} userId User unique ID
*
* @apiSuccess {String} data "success"
*
*/
module.exports.edit = (req,res,next) => {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment