swagger-jsdoc vs apidoc
Generating API Documentation from JavaScript Code Comments
swagger-jsdocapidocSimilar Packages:
Generating API Documentation from JavaScript Code Comments

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.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
swagger-jsdoc1,083,7881,767712 kB433 years agoMIT
apidoc77,4409,705556 kB852 years agoMIT

apidoc vs swagger-jsdoc: Choosing the Right Tool for API Documentation

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.

📝 Comment Syntax: Custom Tags vs OpenAPI Fragments

apidoc uses its own set of JSDoc-like tags that are easy to learn but proprietary.

  • You write @api, @apiParam, @apiSuccess, etc., directly above route handlers.
  • No knowledge of OpenAPI is required, which lowers the barrier for small teams.
/**
 * @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.

  • You write real OpenAPI 3.0 YAML/JSON inline, so your comments mirror the final spec.
  • Requires understanding OpenAPI structure, but ensures correctness and reuse.
/**
 * @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) => {
  // ...
});

📤 Output Format: Standalone HTML vs Machine-Readable Spec

apidoc generates a complete, static HTML website with navigation, search, and examples.

  • Great for human readers — no extra tool needed to view docs.
  • But the output isn’t parseable by other tools; it’s purely for display.
  • You can’t feed it into Postman, generate TypeScript clients, or validate requests against it.

swagger-jsdoc outputs a valid OpenAPI 3.0 JSON or YAML file.

  • This spec can power Swagger UI, Redoc, or Scalar for beautiful interactive docs.
  • More importantly, it becomes a contract: used for mocking, testing, SDK generation, and API gateways.
  • Frontend devs can auto-generate API clients (e.g., with 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));

🔌 Ecosystem Integration: Isolated vs Interoperable

apidoc lives in its own world.

  • No official plugins for request validation, codegen, or CI/CD linting.
  • If your team later adopts OpenAPI, you’ll need to rewrite all comments.
  • Good for throwaway projects or internal tools where docs are “nice to have.”

swagger-jsdoc plugs into the OpenAPI ecosystem.

  • Use swagger-parser to validate your generated spec.
  • Integrate with eslint-plugin-openapi to catch comment errors during development.
  • Share the same spec with backend (for Express middleware validation via 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 }));

🛠️ Maintenance and Evolution

apidoc hasn’t kept pace with modern API practices.

  • Still centered around REST but lacks native support for webhooks, callbacks, or OAuth2 flows beyond basics.
  • No built-in way to reference shared schemas (like a User model used across endpoints).
  • Changes to your API often mean duplicating updates across multiple comment blocks.

swagger-jsdoc leverages OpenAPI’s full feature set.

  • Define reusable components (components.schemas.User) once and $ref them everywhere.
  • Support for security schemes, servers, external docs, and more.
  • As OpenAPI evolves (e.g., Webhooks in 3.1), your tooling benefits automatically.
/**
 * @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'

🤝 Similarities: Shared Developer Experience

Despite their differences, both tools share common ground that makes them appealing over hand-written docs:

1. 📝 Co-location with Code

  • Docs live right next to route handlers, making it harder for them to drift out of sync.
  • Git history shows doc changes alongside logic changes.

2. 🚀 Zero Runtime Overhead

  • Both run at build time or as a dev script — no performance cost in production.

3. 🔧 CLI and Programmatic APIs

  • Easy to integrate into npm scripts or CI pipelines.
{
  "scripts": {
    "docs:apidoc": "apidoc -i src/ -o docs/",
    "docs:swagger": "node scripts/generate-swagger.js"
  }
}

4. 🌐 Framework Agnostic (Mostly)

  • Work with Express, Fastify, Koa, or even plain Node.js HTTP servers.
  • Not tied to any specific frontend framework.

🆚 Summary: Key Differences

Featureapidocswagger-jsdoc
OutputStatic HTML siteValid OpenAPI 3.0 JSON/YAML
Comment StyleProprietary @api* tagsEmbedded OpenAPI fragments
EcosystemStandaloneIntegrates with Swagger tooling
ReusabilityLimited (no shared models)Full $ref support for schemas
Frontend UtilityHuman-readable onlyEnables type-safe clients & mocks
Future-ProofingLow — locked to apidoc formatHigh — aligned with industry standard

💡 The Bottom Line

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.

How to Choose: swagger-jsdoc vs apidoc
  • swagger-jsdoc:

    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.

  • apidoc:

    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.

README for swagger-jsdoc

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 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
  • 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: