2015-08-04 14 views
9

Próbuję dokumentować połączenia router.get z JSDocs. Nie mogę uzyskać dokumentacji, która będzie poprawnie wyświetlana na stronie, jeśli spróbuję dołączyć ją do samego routera.JSDocs: Dokumentowanie tras ekspresowych Node.js

/** 
* Health check 
* @memberof health 
*/ 
router.get('/happy', function(req, res) { 
    res.json({ "status" : "OK" }); 
}); 

Aby rozwiązać ten problem, nadałem funkcjom nazwy.

router.get('/happy', happy); 

/** 
* Health check 
* @memberof health 
*/ 
function happy(req, res) { 
    res.json({ "status" : "OK" }); 
} 

To działa, ale naprawdę chciałbym znaleźć sposób, aby uzyskać pierwszą metodę działania. Czy istnieje sposób udokumentowania pierwszego przykładu? Słowo kluczowe, którego mogę użyć?

Odpowiedz

1

Od trochę Googling, faktycznie nie testowałem.

/** 
* Health check 
* @memberof health 
* @function 
* @name happy 
*/ 
router.get('/happy', function(req, res) { 
    res.json({ "status" : "OK" }); 
}); 
+0

Witam, staram korzystania z tego rozwiązania, ale jest wynikająca nic, hmm. Czy możesz napisać adres URL, gdzie to znajdziesz? – ksugiarto

+0

http://stackoverflow.com/questions/8071897/how-to-document-anonymous-functions-closure-with-jsdoc-toolkit – snuggles08

5

Wykonuję następujące czynności w moim kodzie.

/** 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} middlewear - Express middlewear. 
*/ 
router.get('/login', function(req, res, next) { 
    res.render('login', {title: 'Login', message: 'You must login'}); 
}); 

a wyjście jest: Screenshot

+0

Zrzut ekranu URL zwraca teraz 404 :( – damd

Powiązane problemy