Ninety-nine Pitchers of Malt
Have ideas to improve npm?Join in the discussion! »

swagger-jsdoc
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/swagger-jsdoc package

7.0.0-rc.4 • Public • Published

swagger-jsdoc

This library reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.

npm Downloads CI

Getting started

Imagine having API files like these:

/**
 * @openapi
 * /:
 *   get:
 *     description: Welcome to swagger-jsdoc!
 *     responses:
 *       200:
 *         description: Returns a mysterious string.
 */
app.get('/', (req, res) => {
  res.send('Hello World!');
});

The library will take the contents of @openapi (or @swagger) with the following configuration:

import swaggerJsdoc from 'swagger-jsdoc';

const options = {
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./src/routes*.js'], // files containing annotations as above
};

const openapiSpecification = await swaggerJsdoc(options);

The resulting openapiSpecification will be a swagger tools-compatible (and validated) specification.

swagger-jsdoc example screenshot

System requirements

  • Node.js 12.x or higher

You are viewing swagger-jsdoc v7 which is published in ESM module system.

Installation

npm install swagger-jsdoc --save

Or

yarn add swagger-jsdoc

Supported specifications

  • OpenAPI 3.x
  • Swagger 2

Documentation

Click on the version you are using for further details:

Install

npm i swagger-jsdoc

DownloadsWeekly Downloads

223,444

Version

7.0.0-rc.4

License

MIT

Unpacked Size

68.1 kB

Total Files

9

Last publish

Collaborators

  • avatar
  • avatar
  • avatar