19

如何使用具有以下形式的 jsdoc 记录 API(单个文件)

// api.js

exports.addSocketEvents = function(socket) {
   /**
    * This will do that and ...
    * @param {Object} data Some data
    * @param {string} data.bla Something about bla
    * @param {number} data.n Some number
    */
   socket.on('something_1', function(data) { ... });

   /**
    * Another function that will do ..
    * @param {string} id of something
    */
   socket.on('something_2', function(id) { ... });

   ...
};

exports.addRoutes = function(app) {
    /**
     * PATCH /something/:id/juhu
     * Will do this and that and will respond with ...
     * @param {string} _id Id of bonus document
     */
    app.patch('/something/:id/juhu', function(req, res) {...});

    /**
     * GET /something
     * Will fetch and respond back with ...
     */
    app.get('/something', function(req, res) {...});
    ...
};

我唯一的想法是在@namespace导出和@lends匿名函数之上添加,但这会导致文档为空。

4

1 回答 1

1

我正在使用 Angular,然后是 Angular 文档用于 JSDoc。因此,我正在记录我的父类和类似于以下内容的功能。

/**
 * @class MyApp.Teams
 * @ngdoc class
 * @memberOf MyApp
 * @description
 * Module to handle the interface to the Teams, data and views.
 */

angular.module('MyApp').factory( ...

/**
 * @name TeamRecord
 * @ngdoc factory
 * @memberOf MyApp.Teams
 * @returns Record Clears the Structure to  ""
 * @description
 * Team Data Record structure
 */

因此,使用上面的文字,它可能看起来像:

/**
 * @class MyApp.socketio
 * @ngdoc class
 * @memberOf MyApp
 * @description
 * Module to handle the interface to the Teams, data and views.
 */

/**
 * @name addSocketEvens
 * @ngdoc function
 * @memberOf MyApp.socketio
 * @param {Object} data Some data
 * @param {string} data.bla Something about bla
 * @param {number} data.n Some number
 * @description
 * This will do that and ...
 */
exports.addSocketEvents = function(socket) {
   socket.on('something_1', function(data) { ... });

   /**
    * Another function that will do ..
    * @param {string} id of something
    */
   socket.on('something_2', function(id) { ... });

   ...
};

/**
 * @name addRoutes
 * @ngdoc function
 * @memberOf MyApp.socketio
 * @param {string} _id Id of bonus document
 * @description
 * Will do this and that and will respond with ...
 */
exports.addRoutes = function(app) {
    app.patch('/something/:id/juhu', function(req, res) {...});

    /**
     * GET /something
     * Will fetch and respond back with ...
     */
    app.get('/something', function(req, res) {...});
    ...
};
于 2015-10-23T15:49:28.110 回答