Back to rankings

Surnet/swagger-jsdoc

JavaScript

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

swaggerjsdocswagger-jsdocopenapi
Star Growth
Stars
1.8k
Forks
230
Weekly Growth
โ€”
Issues
29
5001k1.5k
Jan 2023Mar 2024May 2025Jul 2026
Artifactsnpmnpm install swagger-jsdoc
README

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 = swaggerJsdoc(options);

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

swagger-jsdoc example screenshot

System requirements

  • Node.js 20.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
  • AsyncAPI 2.0

Validation of swagger docs

By default swagger-jsdoc tries to parse all docs to it's best capabilities. If you'd like to you can instruct an Error to be thrown instead if validation failed by setting the options flag failOnErrors to true. This is for instance useful if you want to verify that your swagger docs validate using a unit test.

const swaggerJsdoc = require('swagger-jsdoc');

const options = {
  failOnErrors: true, // Whether or not to throw when parsing errors. Defaults to false.
  definition: {
    openapi: '3.0.0',
    info: {
      title: 'Hello World',
      version: '1.0.0',
    },
  },
  apis: ['./src/routes*.js'],
};

const openapiSpecification = swaggerJsdoc(options);

Documentation

Click on the version you are using for further details:

Related repositories
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

PythonPyPIMIT Licensepythonjson
fastapi.tiangolo.com
100.8k9.7k
nocodb/nocodb

๐Ÿ”ฅ ๐Ÿ”ฅ ๐Ÿ”ฅ A Free & Self-hostable Airtable Alternative

TypeScriptnpmOtherautomatic-apiairtable
nocodb.com
64.2k4.9k
fastapi/full-stack-fastapi-template

Full stack, modern web application template. Using FastAPI, React, SQLModel, PostgreSQL, Docker, GitHub Actions, automatic HTTPS and more.

TypeScriptnpmMIT Licensepythonjson
44.4k8.8k
swagger-api/swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.

JavaScriptnpmApache License 2.0swaggerswagger-ui
swagger.io
28.9k9.3k
Redocly/redoc

๐Ÿ“˜ OpenAPI/Swagger-generated API Reference Documentation

TypeScriptnpmMIT Licenseopenapiswagger
redocly.github.io/redoc/
25.8k2.4k
grpc-ecosystem/grpc-gateway

gRPC to JSON proxy generator following the gRPC HTTP spec

GoGo ModulesBSD 3-Clause "New" or "Revised" Licensegogrpc
grpc-ecosystem.github.io/grpc-gateway/
20k2.4k
swagger-api/swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.

MustacheApache License 2.0swaggerswagger-codegen
swagger.io
17.8k6k
scalar/scalar

Scalar is an open-source API platform:ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€๐ŸŒ Modern REST API Clientใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€๐Ÿ“– Beautiful API Referencesใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€ใ€€โœจ 1st-Class OpenAPI/Swagger Support

TypeScriptnpmMIT Licenseapidocs
scalar.com
15.7k902
metersphere/metersphere

MeterSphere ๆ˜ฏๆ–ฐไธ€ไปฃ็š„ๅผ€ๆบๆŒ็ปญๆต‹่ฏ•ๅทฅๅ…ท๏ผŒๅ†…็ฝฎ AI ๅŠฉๆ‰‹๏ผŒ่ฎฉ่ฝฏไปถๆต‹่ฏ•ๅทฅไฝœๆ›ด็ฎ€ๅ•ใ€ๆ›ด้ซ˜ๆ•ˆ๏ผŒไธๅ†ๆˆไธบๆŒ็ปญไบคไป˜็š„็“ถ้ขˆใ€‚

JavaMavenOtherjmetertesting
metersphere.io
13.4k2.8k
swaggo/swag

Automatically generate RESTful API documentation with Swagger 2.0 for Go.

GoGo ModulesMIT Licensegolangswagger
12.9k1.4k
alufers/mitmproxy2swagger

Automagically reverse-engineer REST APIs via capturing traffic

HTMLmitmproxyopenapi
9.6k368
swagger-api/swagger-editor

Swagger Editor

JavaScriptnpmswaggerswagger-editor
editor.swagger.io
9.5k2.4k