我正在努力用JSDocs记录router.get调用。如果我尝试将其附加到路由器调用本身,我无法在页面上正确显示文档。
/**
* Health check
* @memberof health
*/
router.get('/happy', function(req, res) {
res.json({ "status" : "OK" });
});
要解决它,我让函数有了名字。
router.get('/happy', happy);
/**
* Health check
* @memberof health
*/
function happy(req, res) {
res.json({ "status" : "OK" });
}
这有效,但我真的想找到一种方法来获得第一种方法。有没有办法记录第一个例子?我可以使用的关键字?
答案 0 :(得分:9)
我在代码中执行以下操作。
/** Express router providing user related routes
* @module routers/users
* @requires express
*/
/**
* express module
* @const
*/
const express = require('express');
/**
* Express router to mount user related functions on.
* @type {object}
* @const
* @namespace usersRouter
*/
const router = express.Router();
/**
* Route serving login form.
* @name get/login
* @function
* @memberof module:routers/users~usersRouter
* @inner
* @param {string} path - Express path
* @param {callback} middleware - Express middleware.
*/
router.get('/login', function(req, res, next) {
res.render('login', {title: 'Login', message: 'You must login'});
});
输出是:
Screenshot
答案 1 :(得分:1)
从一点点谷歌搜索,还没有真正测试过。
/**
* Health check
* @memberof health
* @function
* @name happy
*/
router.get('/happy', function(req, res) {
res.json({ "status" : "OK" });
});
答案 2 :(得分:0)
如果您未在文件顶部放置“ @module moduleName ”,则jsdoc将不会引用页面上的其他注释,因为它们没有父@module >