1.1.0 • Published 1 year ago

theneo-doc-generator v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

License: MIT

theneo-doc-generator

With this library, you can document your express endpoints using swagger OpenAPI 3 Specification without writing YAML or JSON. You can write comments similar to jsdoc on each endpoint, and the dependecy is going to create the swagger UI.

Table of Contents

  1. Installation
  2. Basic Usage
  3. Basic Examples

Installation

npm i theneo-doc-generator

Basic Usage

// index.js file
const express = require('express');
const theneoDocGenerator = require('theneo-doc-generator');

const options = {
  info: {
    version: '1.0.0',
    title: 'Albums store',
    license: {
      name: 'MIT',
    },
  },
  security: {
    BasicAuth: {
      type: 'http',
      scheme: 'basic',
    },
  },
  // Base directory which we use to locate your JSDOC files
  baseDir: __dirname,
  // Glob pattern to find your jsdoc files (multiple patterns can be added in an array)
  filesPattern: './**/*.js',

  // Get get the api key from the user settings in theneo dashboard
  apiKey: '<Api-Key>',

  // can get api key from project settings
  projectSlug: '<Project-slug>',

  // merge => merge imported sections, endpoints => import only endpoints no sections will be created
  importOptions: 'overwrite',

  // Directory where the generated open api spec will be stored shouldn't be watched by nodemon/pm2
  directory: './uploads',
};



theneoDocGenerator(options);

Basic Examples

  1. Basic configuration options.
const options = {
  info: {
    version: "1.0.0",
    title: "Albums store",
    license: {
      name: "MIT",
    },
  },
  security: {
    BasicAuth: {
      type: "http",
      scheme: "basic",
    },
  },
  baseDir: __dirname,
  // Glob pattern to find your jsdoc files (multiple patterns can be added in an array)
  filesPattern: "./**/*.js",

  // Get get the api key from the user settings in theneo dashboard
  apiKey: "<Api-Key>",

  // can get api key from project settings
  projectSlug: "<Project-slug>",

  // merge => merge imported sections, endpoints => import only endpoints no sections will be created
  importOptions: "overwrite",

  // Directory where the generated open api spec will be stored shouldn't be watched by nodemon/pm2
  directory: "./uploads",
};
  1. Components definition
/**
 * A song type
 * @typedef {object} Song
 * @property {string} title.required - The title
 * @property {string} artist - The artist
 * @property {number} year - The year - double
 */
  1. Endpoint which returns a Songs model array in the response.
/**
 * GET /api/v1/albums
 * @summary This is the summary of the endpoint
 * @tags album
 * @return {array<Song>} 200 - success response - application/json
 */
app.get("/api/v1/albums", (req, res) =>
  res.json([
    {
      title: "abum 1",
    },
  ])
);
  1. Endpoint PUT with body and path params which returns a Songs model array in the response.
/**
 * PUT /api/v1/albums/{id}
 * @summary Update album
 * @tags album
 * @param {string} name.path - name param description
 * @param {Song} request.body.required - songs info
 * @return {array<Song>} 200 - success response - application/json
 */
app.put("/api/v1/albums/:id", (req, res) =>
  res.json([
    {
      title: "abum 1",
    },
  ])
);
  1. Basic endpoint definition with tags, params and basic authentication
/**
 * GET /api/v1/album
 * @summary This is the summary of the endpoint
 * @security BasicAuth
 * @tags album
 * @param {string} name.query.required - name param description
 * @return {object} 200 - success response - application/json
 * @return {object} 400 - Bad request response
 */
app.get("/api/v1/album", (req, res) =>
  res.json({
    title: "abum 1",
  })
);
  1. Basic endpoint definition with code example for response body
/**
 * GET /api/v1/albums
 * @summary This is the summary of the endpoint
 * @tags album
 * @return {array<Song>} 200 - success response - application/json
 * @example response - 200 - success response example
 * [
 *   {
 *     "title": "Bury the light",
 *     "artist": "Casey Edwards ft. Victor Borba",
 *     "year": 2020
 *   }
 * ]
 */
app.get("/api/v1/albums", (req, res) =>
  res.json([
    {
      title: "track 1",
    },
  ])
);
1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago