Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-swagger-generator

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-swagger-generator

Generates swagger doc & ui based on express existing routes.

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.1K
decreased by-1.62%
Maintainers
1
Weekly downloads
 
Created
Source

Express Swagger Generator

Installation
npm i express-swagger-generator --save-dev
Usage
const express = require('express');
const app = express();
const expressSwagger = require('express-swagger-generator')(app);

let options = {
    swaggerDefinition: {
        info: {
            description: 'This is a sample server',
            title: 'Swagger',
            version: '1.0.0',
        },
        host: 'localhost:3000',
        basePath: '/v1',
        produces: [
            "application/json",
            "application/xml"
        ],
        schemes: ['http', 'https']
    },
    basedir: __dirname, //app absolute path
    files: ['./routes/**/*.js'] //Path to the API handle folder
};
expressSwagger(options)
app.listen(3000);

Open http://<app_host>:<app_port>/api-docs in your browser to view the documentation.

How to document the API
/**
 * This function comment is parsed by doctrine
 * @route GET /api
 * @group foo - Operations about user
 * @param {string} email.query.required - username or email
 * @param {string} password.query.required - user's password.
 * @returns {object} 200 - An array of user info
 * @returns {Error}  default - Unexpected error
 */
exports.foo = function() {}

For model definitions:

/**
 * @typedef Point
 * @property {integer} x.required
 * @property {integer} y.required
 * @property {string} color
 */

 // Now I can use it as below:

 /**
  * Insert a point
  * @route POST /api/point
  * @param {Point.model} point.body.required - the new point
  */
More

This module is based on express-swaggerize-ui and Doctrine-File

Keywords

FAQs

Package last updated on 10 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc