Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@haegemonia/express-jsdoc-swagger

haegemonia7623MIT1.0.2TypeScript support: included

Swagger OpenAPI 3.x generator

swagger, swagger-generator, express, jsdoc, node, docs, documentation, swagger-ui, OpenAPI

readme

npm Node.js Package Known Vulnerabilities Maintainability Test Coverage License: MIT npm

express-jsdoc-swagger

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

Prerequisites

This library assumes you are using:

  1. NodeJS
  2. Express.js

Installation

npm i express-jsdoc-swagger

Usage

const express = require('express');
const expressJSDocSwagger = require('express-jsdoc-swagger');

const options = {
  info: {
    version: '1.0.0',
    title: 'Albums store',
    license: {
      name: 'MIT',
    },
  },
  security: {
    BasicAuth: {
      type: 'http',
      scheme: 'basic',
    },
  },
  filesPattern: ['./**/*.js'], // Glob pattern to find your jsdoc files
  swaggerUIPath: '/your-url', // SwaggerUI will be render in this url. Default: '/api-docs'
  baseDir: __dirname,
};

const app = express();
const PORT = 3000;

expressJSDocSwagger(app)(options);

/**
 * GET /api/v1
 * @summary This is the summary or description of the endpoint
 * @return {object} 200 - success response
 */
app.get('/api/v1', (req, res) => res.json({
  success: true,
}));

app.listen(PORT, () => console.log(`Example app listening at http://localhost:${PORT}`));

Examples

  1. Basic configuration

    const options = {
    info: {
     version: '1.0.0',
     title: 'Albums store',
     license: {
       name: 'MIT',
     },
    },
    security: {
     BasicAuth: {
       type: 'http',
       scheme: 'basic',
     },
    },
    filesPattern: ['./**/*.js'], // Glob pattern to find your jsdoc files
    baseDir: __dirname,
    };
  2. 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
    */
  3. Endpoint that returns a Songs model array

    /**
    * GET /api/v1/albums
    * @summary This is the summary or description 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',
    }])
    ));
  4. Basic endpoint definition with tags, params and basic authentication

    /**
    * GET /api/v1/album
    * @summary This is the summary or description 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',
    })
    ));

You can find more examples here, or visit our documentation.

Contributors ✨


Briam Martinez Escobar

💻

Kevin Julián Martínez Escobar

💻

Heung-yeon Oh

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

changelog

1.3.7 / 2019-04-29

  • deps: negotiator@0.6.2
    • Fix sorting charset, encoding, and language with extra parameters

1.3.6 / 2019-04-28

  • deps: mime-types@~2.1.24
    • deps: mime-db@~1.40.0

1.3.5 / 2018-02-28

  • deps: mime-types@~2.1.18
    • deps: mime-db@~1.33.0

1.3.4 / 2017-08-22

  • deps: mime-types@~2.1.16
    • deps: mime-db@~1.29.0

1.3.3 / 2016-05-02

  • deps: mime-types@~2.1.11
    • deps: mime-db@~1.23.0
  • deps: negotiator@0.6.1
    • perf: improve Accept parsing speed
    • perf: improve Accept-Charset parsing speed
    • perf: improve Accept-Encoding parsing speed
    • perf: improve Accept-Language parsing speed

1.3.2 / 2016-03-08

  • deps: mime-types@~2.1.10
    • Fix extension of application/dash+xml
    • Update primary extension for audio/mp4
    • deps: mime-db@~1.22.0

1.3.1 / 2016-01-19

  • deps: mime-types@~2.1.9
    • deps: mime-db@~1.21.0

1.3.0 / 2015-09-29

  • deps: mime-types@~2.1.7
    • deps: mime-db@~1.19.0
  • deps: negotiator@0.6.0
    • Fix including type extensions in parameters in Accept parsing
    • Fix parsing Accept parameters with quoted equals
    • Fix parsing Accept parameters with quoted semicolons
    • Lazy-load modules from main entry point
    • perf: delay type concatenation until needed
    • perf: enable strict mode
    • perf: hoist regular expressions
    • perf: remove closures getting spec properties
    • perf: remove a closure from media type parsing
    • perf: remove property delete from media type parsing

1.2.13 / 2015-09-06

  • deps: mime-types@~2.1.6
    • deps: mime-db@~1.18.0

1.2.12 / 2015-07-30

  • deps: mime-types@~2.1.4
    • deps: mime-db@~1.16.0

1.2.11 / 2015-07-16

  • deps: mime-types@~2.1.3
    • deps: mime-db@~1.15.0

1.2.10 / 2015-07-01

  • deps: mime-types@~2.1.2
    • deps: mime-db@~1.14.0

1.2.9 / 2015-06-08

  • deps: mime-types@~2.1.1
    • perf: fix deopt during mapping

1.2.8 / 2015-06-07

  • deps: mime-types@~2.1.0
    • deps: mime-db@~1.13.0
  • perf: avoid argument reassignment & argument slice
  • perf: avoid negotiator recursive construction
  • perf: enable strict mode
  • perf: remove unnecessary bitwise operator

1.2.7 / 2015-05-10

  • deps: negotiator@0.5.3
    • Fix media type parameter matching to be case-insensitive

1.2.6 / 2015-05-07

  • deps: mime-types@~2.0.11
    • deps: mime-db@~1.9.1
  • deps: negotiator@0.5.2
    • Fix comparing media types with quoted values
    • Fix splitting media types with quoted commas

1.2.5 / 2015-03-13

  • deps: mime-types@~2.0.10
    • deps: mime-db@~1.8.0

1.2.4 / 2015-02-14

  • Support Node.js 0.6
  • deps: mime-types@~2.0.9
    • deps: mime-db@~1.7.0
  • deps: negotiator@0.5.1
    • Fix preference sorting to be stable for long acceptable lists

1.2.3 / 2015-01-31

  • deps: mime-types@~2.0.8
    • deps: mime-db@~1.6.0

1.2.2 / 2014-12-30

  • deps: mime-types@~2.0.7
    • deps: mime-db@~1.5.0

1.2.1 / 2014-12-30

  • deps: mime-types@~2.0.5
    • deps: mime-db@~1.3.1

1.2.0 / 2014-12-19

  • deps: negotiator@0.5.0
    • Fix list return order when large accepted list
    • Fix missing identity encoding when q=0 exists
    • Remove dynamic building of Negotiator class

1.1.4 / 2014-12-10

  • deps: mime-types@~2.0.4
    • deps: mime-db@~1.3.0

1.1.3 / 2014-11-09

  • deps: mime-types@~2.0.3
    • deps: mime-db@~1.2.0

1.1.2 / 2014-10-14

1.1.1 / 2014-09-28

  • deps: mime-types@~2.0.2
    • deps: mime-db@~1.1.0
  • deps: negotiator@0.4.8
    • Fix all negotiations to be case-insensitive
    • Stable sort preferences of same quality according to client order

1.1.0 / 2014-09-02

  • update mime-types

1.0.7 / 2014-07-04

  • Fix wrong type returned from type when match after unknown extension

1.0.6 / 2014-06-24

1.0.5 / 2014-06-20

  • fix crash when unknown extension given

1.0.4 / 2014-06-19

  • use mime-types

1.0.3 / 2014-06-11

1.0.2 / 2014-05-29

1.0.1 / 2014-01-18

  • Identity encoding isn't always acceptable
  • deps: negotiator@~0.4.0

1.0.0 / 2013-12-27

  • Genesis