apidoc and swagger-jsdoc are both tools that generate interactive API documentation by parsing specially formatted comments in JavaScript (or TypeScript) source code. They aim to keep documentation close to implementation, reduce duplication, and produce human-readable specs without writing raw OpenAPI/Swagger YAML or JSON. However, they target different documentation standards and ecosystems: apidoc uses its own lightweight format and produces standalone HTML docs, while swagger-jsdoc builds valid OpenAPI 3.0 (or Swagger 2.0) specifications that integrate with the broader Swagger ecosystem like Swagger UI or Redoc.
Both apidoc and swagger-jsdoc help you avoid writing separate API documentation by extracting structured info from code comments. But they diverge sharply in output format, ecosystem alignment, and long-term maintainability. Let’s break down what really matters when you’re building production-grade APIs.
apidoc uses its own set of JSDoc-like tags that are easy to learn but proprietary.
@api, @apiParam, @apiSuccess, etc., directly above route handlers./**
* @api {get} /user/:id Get User Info
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
*/
app.get('/user/:id', (req, res) => {
// ...
});
swagger-jsdoc embeds fragments of OpenAPI spec inside JSDoc comments using @openapi or @swagger.
/**
* @openapi
* /user/{id}:
* get:
* summary: Get User Info
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: integer
* responses:
* '200':
* description: A user object
* content:
* application/json:
* schema:
* type: object
* properties:
* firstname: { type: string }
* lastname: { type: string }
*/
app.get('/user/:id', (req, res) => {
// ...
});
apidoc generates a complete, static HTML website with navigation, search, and examples.
swagger-jsdoc outputs a valid OpenAPI 3.0 JSON or YAML file.
openapi-typescript), reducing manual typing errors.// swagger-jsdoc: generate spec, then serve via Swagger UI
const swaggerSpec = swaggerJsdoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
apidoc lives in its own world.
swagger-jsdoc plugs into the OpenAPI ecosystem.
swagger-parser to validate your generated spec.eslint-plugin-openapi to catch comment errors during development.express-openapi-validator) and frontend (for type-safe API calls).// Example: Validate incoming requests using the same spec
const validator = require('express-openapi-validator');
app.use(validator({ apiSpec: swaggerSpec }));
apidoc hasn’t kept pace with modern API practices.
User model used across endpoints).swagger-jsdoc leverages OpenAPI’s full feature set.
components.schemas.User) once and $ref them everywhere./**
* @openapi
* components:
* schemas:
* User:
* type: object
* properties:
* id: { type: integer }
* name: { type: string }
*/
// Later, reference it:
// responses:
// '200':
// content:
// application/json:
// schema:
// $ref: '#/components/schemas/User'
Despite their differences, both tools share common ground that makes them appealing over hand-written docs:
{
"scripts": {
"docs:apidoc": "apidoc -i src/ -o docs/",
"docs:swagger": "node scripts/generate-swagger.js"
}
}
| Feature | apidoc | swagger-jsdoc |
|---|---|---|
| Output | Static HTML site | Valid OpenAPI 3.0 JSON/YAML |
| Comment Style | Proprietary @api* tags | Embedded OpenAPI fragments |
| Ecosystem | Standalone | Integrates with Swagger tooling |
| Reusability | Limited (no shared models) | Full $ref support for schemas |
| Frontend Utility | Human-readable only | Enables type-safe clients & mocks |
| Future-Proofing | Low — locked to apidoc format | High — aligned with industry standard |
Use apidoc if you’re building a small internal API and just need a quick, readable HTML page for your team — and you’re confident you’ll never need machine-readable contracts.
Use swagger-jsdoc if you’re working on anything customer-facing, cross-team, or likely to grow. The upfront learning curve of OpenAPI pays off through automation, type safety, and tooling that scales with your project.
In today’s frontend landscape — where APIs drive everything from React hooks to mobile apps — treating your API spec as a first-class artifact (not just documentation) is non-negotiable. That’s why swagger-jsdoc is the more sustainable choice for professional teams.
Choose swagger-jsdoc if your project must produce valid OpenAPI 3.0 (or Swagger 2.0) definitions that plug into the wider Swagger ecosystem — including Swagger UI, Postman imports, contract validation, or client SDK generation. It’s ideal when documentation must serve as a machine-readable contract between frontend and backend teams, or when you’re already using OpenAPI elsewhere in your pipeline.
Choose apidoc if you need a simple, zero-config way to generate clean, self-contained HTML documentation directly from JSDoc-style comments and don’t require strict OpenAPI compliance. It’s well-suited for internal APIs or teams that prioritize ease of setup over interoperability with tooling that expects standard OpenAPI specs. Avoid it if your organization mandates OpenAPI/Swagger for contract testing, code generation, or gateway integration.
This library reads your JSDoc-annotated source code and generates an OpenAPI (Swagger) specification.
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.

You are viewing swagger-jsdoc v6 which is published in CommonJS module system.
npm install swagger-jsdoc --save
Or
yarn add swagger-jsdoc
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);
Click on the version you are using for further details: