A powerful CLI tool for automatically generating OpenAPI 3.0 documentation from your JavaScript and TypeScript source code by parsing JSDoc comments and OpenAPI annotations.
- π Easy to use: Simple CLI interface with intuitive options
- π JSDoc parsing: Extracts OpenAPI documentation from JSDoc comments
- π― Pattern matching: Flexible file pattern matching with glob support
- π§ Configurable: Extensive configuration options
- π€ Multiple formats: Output in JSON or YAML format
- π« Exclude patterns: Skip unwanted files and directories
- π Debug mode: Detailed logging for troubleshooting
- β‘ Bootstrap support: Load configuration files and constants
npm install -g openapi-docs-generatornpm install openapi-docs-generatornpx openapi-docs-generator [options] [paths...]# Generate docs for all JS files in src directory
openapi-docs-generator ./src
# Generate docs for TypeScript files
openapi-docs-generator --pattern "*.ts" ./src
# Output to specific file
openapi-docs-generator --output ./docs/openapi.yaml ./src
# Output in JSON format
openapi-docs-generator --format json ./src# Exclude specific directories and files
openapi-docs-generator --exclude node_modules --exclude dist ./src
# Use custom file patterns
openapi-docs-generator --pattern "*/*.ts" --exclude "**/*.test.ts" ./src
# Enable debug mode
openapi-docs-generator --debug ./src
# Load bootstrap files
openapi-docs-generator --bootstrap ./config/constants.js ./src| Option | Short | Description | Example |
|---|---|---|---|
--config |
-c |
Generator configuration | -c operationId.hash=false |
--output |
-o |
Output file path | --output openapi.yaml |
--exclude |
-e |
Exclude paths | --exclude node_modules |
--pattern |
-n |
File pattern to scan | --pattern "*.ts" |
--bootstrap |
-b |
Bootstrap files | --bootstrap config/constants.js |
--processor |
-p |
Additional processors | --processor custom-processor |
--format |
-f |
Output format (json/yaml/auto) | --format json |
--debug |
-d |
Enable debug logging | --debug |
--version |
OpenAPI version | --version 3.1.0 |
|
--help |
-h |
Show help message | --help |
The tool parses JSDoc comments and OpenAPI annotations to generate documentation. Here are some examples:
/**
* @OA\Info(
* title="My API",
* version="1.0.0",
* description="A sample API"
* )
*//**
* @OA\Get(
* path="/users",
* summary="Get all users",
* tags={"users"}
* )
*/
function getUsers() {
// Implementation
}/**
* @OA\Schema(
* schema="User",
* type="object",
* properties={
* "id": {"type": "integer"},
* "name": {"type": "string"},
* "email": {"type": "string", "format": "email"}
* }
* )
*/You can pass configuration options using the --config flag:
openapi-docs-generator --config operationId.hash=false --config info.title="My API"Bootstrap files allow you to define constants and configuration that will be loaded before processing:
openapi-docs-generator --bootstrap ./config/api-constants.js ./srcopenapi-docs-generator --format json ./srcopenapi-docs-generator --format yaml ./srcopenapi-docs-generator --output ./docs/api.json ./src # JSON format
openapi-docs-generator --output ./docs/api.yaml ./src # YAML formatopenapi-docs-generator \
--exclude node_modules \
--exclude dist \
--pattern "*.js" \
--output ./docs/openapi.yaml \
./srcopenapi-docs-generator \
--exclude node_modules \
--exclude "**/*.test.ts" \
--pattern "*.ts" \
--format json \
--output ./docs/openapi.json \
./srcopenapi-docs-generator \
--debug \
--bootstrap ./config/constants.js \
--exclude node_modules \
./srcThe tool can also be used programmatically:
const { OpenApiGenerator, Logger } = require('openapi-docs-generator');
const logger = new Logger(true); // Enable debug
const generator = new OpenApiGenerator(logger);
const openapi = generator
.setVersion('3.0.0')
.setConfig({ 'operationId.hash': false })
.generate(['./src/api.js']);
// Output as JSON
console.log(openapi.toJson());
// Output as YAML
console.log(openapi.toYaml());
// Save to file
openapi.saveAs('./docs/openapi.yaml', 'yaml');- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
ISC
If you encounter any issues or have questions, please open an issue on GitHub.