API Documentation Generator

1.2.0 · active · verified Tue Apr 21

apidoc is a command-line utility and programmatic library for generating comprehensive RESTful web API documentation directly from comments embedded within source code. It supports a wide array of programming languages by parsing specialized JSDoc-style comments (e.g., `/** ... */` for JavaScript/Java/C#, `""" ... """` for Python) marked with `@api` tags. The current stable version is 1.2.0, released in February 2024, reflecting a consistent, moderate release cadence focused on stability and feature enhancements. Its key differentiators include a language-agnostic parsing engine that understands various comment styles, a flexible plugin architecture for extending functionality (such as integrating API schemas), and robust programmatic integration options for custom build pipelines. The output is static HTML documentation, making it easy to host and integrate into any project.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic API documentation generation using `createDoc`, illustrating how to specify source/destination paths, control output, and access the parsed documentation data and project information.

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

// Resolve paths relative to the current script execution
const projectRoot = path.resolve(__dirname, '..'); 
// Using 'example' folder from a cloned apidoc repository for demonstration
const srcPath = path.resolve(projectRoot, 'example'); 
const destPath = path.resolve(projectRoot, 'docs');

console.log(`Attempting to generate API documentation from: ${srcPath} to: ${destPath}`);

const docResult = createDoc({
  src: srcPath,
  dest: destPath,
  // Set dryRun to true to parse and return data without writing files to disk
  dryRun: false,
  // Set silent to true to suppress apidoc's console output during generation
  silent: false,
  // Optional: Define custom parsing options or template paths here
});

if (typeof docResult !== 'boolean') {
  console.log('API documentation generated successfully!');
  console.log('Parsed API definitions count:', docResult.data.length);
  console.log('Project information:', docResult.project.name, docResult.project.version);
} else {
  console.error('Failed to generate API documentation. Check logs for detailed errors and ensure source paths are correct and comments are well-formed.');
}

view raw JSON →