Code Monkey home page Code Monkey logo

jsdoc-plugin-mongoose's Introduction

jsdoc-plugin-mongoose

Build Status Code Style: prettier

This repository contains a JSDoc plugin for use with Mongoose.

This plugin will automatically generate JSDoc documentation from Mongoose schemas for corresponding models, including data types of fields and contextual descriptions.

Example

Given a Mongoose schema, defined as below, appropriate documentation will be generated.

const mongoose = require('mongoose');

/**
 * Blog post
 */
const BlogSchema = new mongoose.Schema({
  /**
   * Title of the blog post which will be used as the header.
   */
  title: String,
  /**
   * Array of comments, each with a body and date.
   */
  comments: [{body: String, date: Date}],
  date: {type: Date, default: Date.now},
  hidden: Boolean
});

/**
 * Adds a comment to a blog post.
 * @param {String} body The body of the comment
 */
BlogSchema.methods.addComment = function(body) {};

/**
 * Finds blog posts from today.
 */
BlogSchema.statics.findCurrentBlogPosts = function() {};

module.exports = mongoose.model('Blog', BlogSchema);

The resulting documentation will include top-level schema paths as members of the inferred class:

Class: Blog

Blog post

Extends

mongoose.Model

Members

comments :Array.<Object>

Array of comments, each with a body and date.

date :Date
hidden :Boolean
title :String

Title of the blog post which will be used as the header.

Methods

findCurrentBlogPosts()

Finds blog posts from today.

addComment(body)

Adds a comment to a blog post.

Usage

To use this plugin, include it as one of the plugins in your JSDoc configuration. Uses of new mongoose.Schema in your code will be detected and result in documentation being generated for the corresponding model and its members (see example above).

  1. Install this plugin globally or as a dev dependency, or copy it to the plugins folder located in the JSDoc installation folder.
    $ git clone https://github.com/sgilroy/jsdoc-plugin-mongoose
  2. Include the plugin in your jsdoc-conf.js file. If the plugin is not installed in the plugins folder, specify a relative or absolute path to the plugin.
    module.exports = {
      plugins: ['plugins/jsdoc-plugin-mongoose']
    };
  3. Run JSDoc from the command line and pass the configuration file to it.
    $ jsdoc -c jsdoc-conf.js

Using @schemaof

The plugin will generally infer that properties are part of a mongoose schema and thus associate them with the appropriate class automatically if the property is defined directly as a child of a schema declaration. For example:

const BlogSchema = new mongoose.Schema({
  /**
   * Title of the blog post which will be used as the header.
   */
  title: String
});

Here the title is inferred to be a member of the Blog class by being part of the BlogSchema declaration. However, you may want to define some or all of the schema properties separately from creating the schema. In such cases, the @schemaof tag should be used to tell the plugin to treat the properties as part of a mongoose schema definition. For example:

/**
 * @schemaof Blog
 */
const blogSchemaObject = {
  /**
   * Title of the blog post which will be used as the header.
   */
  title: String
};
const BlogSchema = new mongoose.Schema(blogSchemaObject);

jsdoc-plugin-mongoose's People

Contributors

sgilroy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

x42en

jsdoc-plugin-mongoose's Issues

Can you put this project to npm?

This is a great plugin, I like it very much.
But it's not available on Node package manager.
Can you help to publish this plugin to npm, so people can use this plugin in a more convenience way.
And more people will know this great plugin.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.