apidoc vs swagger-jsdoc
Generating API Documentation from JavaScript Code Comments
apidocswagger-jsdocSimilar 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
apidoc77,8679,677556 kB853 years agoMIT
swagger-jsdoc01,789712 kB473 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: apidoc vs swagger-jsdoc

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

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

README for apidoc

apiDoc

apiDoc creates a documentation from API descriptions in your source code.

validate NPM version Join the chat at https://gitter.im/apidoc/talk

Documentation: apidocjs.com

Live DEMO

Installation

$ npm install -g apidoc

Usage

Add some apidoc comments anywhere in your source code:

/**
 * @api {get} /user/:id Request User information
 * @apiName GetUser
 * @apiGroup User
 *
 * @apiParam {Number} id User's unique ID.
 *
 * @apiSuccess {String} firstname Firstname of the User.
 * @apiSuccess {String} lastname  Lastname of the User.
 */

Now generate the documentation from src/ into doc/.

$ apidoc -i src/ -o doc/

This repository contains and example folder from which you can generate a very complete documentation on an example api endpoint. It also contains best practice hints (in the footer.md file).

$ git clone https://github.com/apidoc/apidoc && cd apidoc
$ npm install --prod
$ ./bin/apidoc -i example -o /tmp/doc
$ $BROWSER /tmp/doc

Programmatic usage

You can generate the documentation programmatically:

import path from 'path'
import { createDoc } from 'apidoc'

const doc = createDoc({
  src: path.resolve(__dirname, 'src'),
  dest: path.resolve(__dirname, 'doc'), // can be omitted if dryRun is true
  // if you don't want to generate the output files:
  dryRun: true,
  // if you don't want to see any log output:
  silent: true,
})

if (typeof doc !== 'boolean') {
  // Documentation was generated!
  console.log(doc.data) // the parsed api documentation object
  console.log(doc.project) // the project information
}

Install type definitions (see @types/apidoc):

$ npm install -D @types/apidoc

Docker image

You can use apidoc in Docker like this:

# first build the image after cloning this repository
docker build -t apidoc/apidoc .
# run it
docker run --rm -v $(pwd):/home/node/apidoc apidoc/apidoc -o outputdir -i inputdir

Supported programming languages

  • C#, Go, Dart, Java, JavaScript, PHP, Scala (all DocStyle capable languages):

    /**
      * This is a comment.
      */
    
  • Clojure:

    ;;;;
    ;; This is a comment.
    ;;;;
    
  • CoffeeScript:

    ###
    This is a comment.
    ###
    
  • Elixir:

    #{
    # This is a comment.
    #}
    
  • Erlang:

    %{
    % This is a comment.
    %}
    
  • Perl

    #**
    # This is a comment.
    #*
    
    =pod
    This is a comment.
    =cut
    
  • Python

    """
    This is a comment.
    """
    
  • Ruby

    =begin
    This is a comment.
    =end
    

Plugins (extend apiDoc)

apiDoc will auto include installed plugins.

  • apidoc-plugin-schema Generates and inject apidoc elements from api schemas. npm install apidoc-plugin-schema

For details and an example on how to implement your own plugin, please view apidoc-plugin-test.

Support

Please create a new issue if you have a suggestion/question or if you found a problem/bug.

Contributing

apiDoc is a collaborative project. Pull requests are welcome. Please see the CONTRIBUTING file.

Build tools

Integration

Converter