Skip to content

Generates swagger/openapi specification based on jsDoc comments and YAML files.

License

Notifications You must be signed in to change notification settings

imsamurai/swagger-jsdoc

This branch is 4 commits ahead of, 83 commits behind Surnet/swagger-jsdoc:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c25f9ab · Jun 2, 2021
Feb 16, 2021
Apr 16, 2021
Mar 12, 2021
Apr 16, 2021
Jun 2, 2021
Apr 16, 2021
Oct 8, 2020
Jul 27, 2018
Nov 27, 2020
Oct 18, 2020
Dec 16, 2020
Oct 28, 2020
Oct 8, 2020
Sep 25, 2020
Mar 7, 2021
Jun 9, 2015
Apr 16, 2021
Oct 28, 2020
Apr 16, 2021
Mar 11, 2021
Mar 7, 2021

Repository files navigation

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:

const swaggerJsdoc = require('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 v6 which is published in CommonJS module system.

Installation

npm install swagger-jsdoc --save

Or

yarn add swagger-jsdoc

Supported specifications

  • OpenAPI 3.x
  • Swagger 2

$ref dereference

If you want to dereference all refs in specification set dereference flag in options.

const options = {
  dereference: true,
};

Breaking changes

7.x

  • Result of swaggerJsdoc() is async

Documentation

Click on the version you are using for further details:

About

Generates swagger/openapi specification based on jsDoc comments and YAML files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%