JSDoc + Mongoose : how to document Mongoose models? JSDoc + Mongoose : how to document Mongoose models? mongoose mongoose

JSDoc + Mongoose : how to document Mongoose models?


I found @class (or its synonym @constructor) works for schema properties:

/** * @class MyClient */var MyClientSchema = new mongoose.Schema({    fist_name: {        type: String    },    phone_number: {        type: String    }});var MyClient = mongoose.model('MyClient', MyClientSchema);

The @alias works for methods declared the old way:

/** * @alias MyClient.prototype.getDescription */MyClientSchema.method('getDescription', function () {    return this.first_name + " " + this.phone_number;});

However, you can mark all methods as part of MyClient at once if you use the new way of declaring methods:

/** * @class MyClient * @mixes {MyClientSchema.methods} */var MyClientSchema = new mongoose.Schema({ .../** @mixin */MyClientSchema.methods;MyClientSchema.methods.getDescription = function () {    return this.first_name + " " + this.phone_number;};

All the above tested in latest WebStorm version (2018.2). It works.

Things which do not work:

  • Mongoose built-in methods like .find() or .save()
  • The .methods syntax highlight works but code completion doesn't.

Updates are welcome!


Although it might not fit your specific requirement, this jet brains tutorial in the official documentation explains most of what you need

https://www.jetbrains.com/help/webstorm/2017.1/creating-jsdoc-comments.html

for example,

/** * MyClientSchema schema * @constructor MyClient */var MyClientSchema = new mongoose.Schema({        fist_name: {            type: String        },        phone_number: {            type: String        }    });

and the following js might be a guide foe you to do almost everything you need

http://nagyv.github.io/estisia-wall/models.js.html