API Documentation Generator
Generate production-ready OpenAPI 3.1 specifications and documentation from your codebase.
Workflow
Phase 1: Discovery
Detect framework by scanning for:
package.json → Express, NestJS, Fastify, Hono
requirements.txt / pyproject.toml → FastAPI, Flask, Django REST
go.mod → Gin, Echo, Chi, Fiber
Gemfile → Rails API
pom.xml / build.gradle → Spring Boot
Cargo.toml → Axum, Actix-web
Find API entry points:
# Common patterns to search
app.get|post|put|patch|delete # Express/Fastify
@app.route|@router # Flask/FastAPI
@GetMapping|@PostMapping # Spring
router.GET|POST # Gin/Echo
resources|get|post # Rails
@Controller|@Get|@Post # NestJS
Extract endpoint metadata:
- HTTP method and path
- Path parameters (
:id, {id}, <id>)
- Query parameters
- Request body schema
- Response schemas and status codes
- Authentication requirements
- Middleware/decorators
Phase 2: Schema Extraction
Type definitions → OpenAPI components/schemas:
- TypeScript interfaces/types
- Python Pydantic models, dataclasses, TypedDict
- Go structs with json tags
- Java/Kotlin DTOs
- Ruby serializers
Validation rules → OpenAPI constraints:
- Required fields
- Min/max values
- String patterns (email, uuid, etc.)
- Enums
- Array constraints
Existing documentation:
- JSDoc/TSDoc comments
- Python docstrings
- Go doc comments
- Swagger/OpenAPI annotations
- README files
Phase 3: OpenAPI Generation
Generate openapi.yaml with:
openapi: 3.1.0
info:
title: <extracted from package.json/pyproject.toml or ask>
version: <from version file or git tag>
description: <from README or generate>
servers:
- url: <detect from env/config or use placeholder>
paths:
/endpoint:
get:
summary: <from docstring or generate>
description: <detailed description>
operationId: <function name>
tags: [<from route grouping>]
parameters: [<extracted>]
requestBody: <if applicable>
responses:
'200':
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ResponseType'
example: <generate realistic example>
'400': <validation errors>
'401': <if auth required>
'404': <if path params>
'500': <server error>
security: [<detected auth>]
components:
schemas: <all extracted types>
securitySchemes: <detected auth methods>
Phase 4: Documentation Output
Based on $ARGUMENTS or default to all:
OpenAPI Spec (openapi.yaml):
- Valid OpenAPI 3.1
- Realistic examples for all schemas
- Comprehensive error responses
Markdown (API.md):
- Table of contents
- Authentication section
- Endpoint reference with examples
- Schema definitions
- Error codes
Postman Collection (postman.json):
- Importable collection
- Environment variables
- Pre-configured requests
Phase 5: Validation
Before finalizing, validate:
Spec validity:
npx @redocly/cli lint openapi.yaml
Or if not available, validate structure manually.
Coverage check: List any endpoints found but not documented
Quality checks:
- All endpoints have descriptions
- All parameters documented
- Response examples provided
- Auth requirements specified
Framework-Specific Patterns
See reference.md for detailed extraction patterns per framework.
Output Format Selection
| Argument |
Output |
openapi |
OpenAPI 3.1 YAML only |
markdown |
API.md documentation |
postman |
Postman collection JSON |
all (default) |
All formats |
html |
Redoc-ready HTML |
Example Usage
/api-docs # Auto-detect, generate all formats
/api-docs fastapi openapi # FastAPI project, OpenAPI only
/api-docs express markdown # Express project, Markdown only
Quality Standards
Generated documentation MUST include:
1---2name: api-docs3description: Generate OpenAPI 3.1 specs and documentation from code. Supports Express, FastAPI, Flask, NestJS, Spring Boot, Gin, Rails, and more. Use when documenting APIs, creating OpenAPI specs, or generating API reference docs.4---56# API Documentation Generator78Generate production-ready OpenAPI 3.1 specifications and documentation from your codebase.910## Workflow1112### Phase 1: Discovery13141. **Detect framework** by scanning for:15 - `package.json` → Express, NestJS, Fastify, Hono16 - `requirements.txt` / `pyproject.toml` → FastAPI, Flask, Django REST17 - `go.mod` → Gin, Echo, Chi, Fiber18 - `Gemfile` → Rails API19 - `pom.xml` / `build.gradle` → Spring Boot20 - `Cargo.toml` → Axum, Actix-web21222. **Find API entry points**:23 ```24 # Common patterns to search25 app.get|post|put|patch|delete # Express/Fastify26 @app.route|@router # Flask/FastAPI27 @GetMapping|@PostMapping # Spring28 router.GET|POST # Gin/Echo29 resources|get|post # Rails30 @Controller|@Get|@Post # NestJS31 ```32333. **Extract endpoint metadata**:34 - HTTP method and path35 - Path parameters (`:id`, `{id}`, `<id>`)36 - Query parameters37 - Request body schema38 - Response schemas and status codes39 - Authentication requirements40 - Middleware/decorators4142### Phase 2: Schema Extraction43441. **Type definitions** → OpenAPI components/schemas:45 - TypeScript interfaces/types46 - Python Pydantic models, dataclasses, TypedDict47 - Go structs with json tags48 - Java/Kotlin DTOs49 - Ruby serializers50512. **Validation rules** → OpenAPI constraints:52 - Required fields53 - Min/max values54 - String patterns (email, uuid, etc.)55 - Enums56 - Array constraints57583. **Existing documentation**:59 - JSDoc/TSDoc comments60 - Python docstrings61 - Go doc comments62 - Swagger/OpenAPI annotations63 - README files6465### Phase 3: OpenAPI Generation6667Generate `openapi.yaml` with:6869```yaml70openapi: 3.1.071info:72 title: <extracted from package.json/pyproject.toml or ask>73 version: <from version file or git tag>74 description: <from README or generate>75servers:76 - url: <detect from env/config or use placeholder>77paths:78 /endpoint:79 get:80 summary: <from docstring or generate>81 description: <detailed description>82 operationId: <function name>83 tags: [<from route grouping>]84 parameters: [<extracted>]85 requestBody: <if applicable>86 responses:87 '200':88 description: Success89 content:90 application/json:91 schema:92 $ref: '#/components/schemas/ResponseType'93 example: <generate realistic example>94 '400': <validation errors>95 '401': <if auth required>96 '404': <if path params>97 '500': <server error>98 security: [<detected auth>]99components:100 schemas: <all extracted types>101 securitySchemes: <detected auth methods>102```103104### Phase 4: Documentation Output105106Based on `$ARGUMENTS` or default to all:1071081. **OpenAPI Spec** (`openapi.yaml`):109 - Valid OpenAPI 3.1110 - Realistic examples for all schemas111 - Comprehensive error responses1121132. **Markdown** (`API.md`):114 - Table of contents115 - Authentication section116 - Endpoint reference with examples117 - Schema definitions118 - Error codes1191203. **Postman Collection** (`postman.json`):121 - Importable collection122 - Environment variables123 - Pre-configured requests124125### Phase 5: Validation126127Before finalizing, validate:1281291. **Spec validity**:130 ```bash131 npx @redocly/cli lint openapi.yaml132 ```133 Or if not available, validate structure manually.1341352. **Coverage check**: List any endpoints found but not documented1361373. **Quality checks**:138 - All endpoints have descriptions139 - All parameters documented140 - Response examples provided141 - Auth requirements specified142143## Framework-Specific Patterns144145See [reference.md](reference.md) for detailed extraction patterns per framework.146147## Output Format Selection148149| Argument | Output |150|----------|--------|151| `openapi` | OpenAPI 3.1 YAML only |152| `markdown` | API.md documentation |153| `postman` | Postman collection JSON |154| `all` (default) | All formats |155| `html` | Redoc-ready HTML |156157## Example Usage158159```160/api-docs # Auto-detect, generate all formats161/api-docs fastapi openapi # FastAPI project, OpenAPI only162/api-docs express markdown # Express project, Markdown only163```164165## Quality Standards166167Generated documentation MUST include:168- [ ] All public endpoints documented169- [ ] Request/response examples for each endpoint170- [ ] Authentication requirements clearly stated171- [ ] Error responses documented (4xx, 5xx)172- [ ] Parameter constraints (required, types, validation)173- [ ] Consistent naming and formatting