API Documentation Generator
This skill automatically generates OpenAPI 3.0 (Swagger) documentation from API route files in your codebase.
When to Use This Skill
- User asks to generate API documentation
- Working with REST API endpoints
- Need to create or update OpenAPI/Swagger specs
- Setting up API documentation for Express, FastAPI, Flask, NestJS, or similar frameworks
Instructions
1. Discover API Routes
Search the codebase for API route definitions:
- Express/Node.js: Look for
app.get(), app.post(), router.get(), etc.
- FastAPI/Python: Look for
@app.get(), @router.post(), decorators
- Flask: Look for
@app.route() decorators
- NestJS: Look for
@Get(), @Post(), @Controller() decorators
- Rails: Look for routes in
config/routes.rb
Use Glob to find route files (e.g., **/*routes*.{js,ts,py}, **/controllers/**/*.{js,ts})
2. Analyze Route Patterns
For each discovered route, extract:
- HTTP Method: GET, POST, PUT, PATCH, DELETE
- Path: The endpoint URL (e.g.,
/api/users/:id)
- Parameters: Path params, query params, request body
- Response: Expected response structure
- Authentication: Whether auth is required
- Description: Comments or docstrings near the route
3. Generate OpenAPI Specification
Create or update an OpenAPI 3.0 specification file (typically openapi.yaml or swagger.json):
- Start with the template from
templates/openapi-3.0.yaml
- Map each route to an OpenAPI path object
- Define request/response schemas using JSON Schema
- Include parameter definitions (path, query, body)
- Add authentication schemes if detected (Bearer, API Key, OAuth2)
- Group endpoints by tags (e.g., "Users", "Products", "Auth")
4. Validate Completeness
Check that the generated documentation includes:
- All discovered endpoints
- Accurate HTTP methods and paths
- Request/response examples where possible
- Error responses (400, 401, 404, 500, etc.)
- Security requirements
5. Output Location
- Save as
openapi.yaml in the project root, or
- Place in
docs/ or api/ directory if those exist
- Ask user for preferred location if unclear
Framework-Specific Notes
Express/Node.js
- Check for route middleware that might affect auth/validation
- Look for request validators (Joi, express-validator, etc.)
- Extract JSDoc comments for endpoint descriptions
FastAPI
- FastAPI auto-generates OpenAPI docs, but this skill can enhance them
- Extract Pydantic models for request/response schemas
- Check for
response_model and status_code parameters
NestJS
- Look for DTOs (Data Transfer Objects) for schemas
- Check for Swagger decorators (
@ApiOperation, @ApiResponse)
- Extract metadata from controller and method decorators
Best Practices
- Use existing schemas: If the codebase has TypeScript interfaces, Pydantic models, or similar, use them for accurate schemas
- Include examples: Add request/response examples from tests if available
- Group logically: Organize endpoints by resource or feature area using tags
- Version appropriately: Use the API version from the codebase (e.g., "1.0.0")
- Add descriptions: Use code comments/docstrings for endpoint descriptions
Supporting Files
templates/openapi-3.0.yaml: Base OpenAPI template
examples.md: Framework-specific examples
1---2name: api-documentation-generator3description: Generates OpenAPI/Swagger documentation from API route files. Use when working with REST APIs, Express routes, FastAPI endpoints, or when user requests API documentation.4---56# API Documentation Generator78This skill automatically generates OpenAPI 3.0 (Swagger) documentation from API route files in your codebase.910## When to Use This Skill1112- User asks to generate API documentation13- Working with REST API endpoints14- Need to create or update OpenAPI/Swagger specs15- Setting up API documentation for Express, FastAPI, Flask, NestJS, or similar frameworks1617## Instructions1819### 1. Discover API Routes2021Search the codebase for API route definitions:2223- **Express/Node.js**: Look for `app.get()`, `app.post()`, `router.get()`, etc.24- **FastAPI/Python**: Look for `@app.get()`, `@router.post()`, decorators25- **Flask**: Look for `@app.route()` decorators26- **NestJS**: Look for `@Get()`, `@Post()`, `@Controller()` decorators27- **Rails**: Look for routes in `config/routes.rb`2829Use Glob to find route files (e.g., `**/*routes*.{js,ts,py}`, `**/controllers/**/*.{js,ts}`)3031### 2. Analyze Route Patterns3233For each discovered route, extract:3435- **HTTP Method**: GET, POST, PUT, PATCH, DELETE36- **Path**: The endpoint URL (e.g., `/api/users/:id`)37- **Parameters**: Path params, query params, request body38- **Response**: Expected response structure39- **Authentication**: Whether auth is required40- **Description**: Comments or docstrings near the route4142### 3. Generate OpenAPI Specification4344Create or update an OpenAPI 3.0 specification file (typically `openapi.yaml` or `swagger.json`):4546- Start with the template from `templates/openapi-3.0.yaml`47- Map each route to an OpenAPI path object48- Define request/response schemas using JSON Schema49- Include parameter definitions (path, query, body)50- Add authentication schemes if detected (Bearer, API Key, OAuth2)51- Group endpoints by tags (e.g., "Users", "Products", "Auth")5253### 4. Validate Completeness5455Check that the generated documentation includes:5657- All discovered endpoints58- Accurate HTTP methods and paths59- Request/response examples where possible60- Error responses (400, 401, 404, 500, etc.)61- Security requirements6263### 5. Output Location6465- Save as `openapi.yaml` in the project root, or66- Place in `docs/` or `api/` directory if those exist67- Ask user for preferred location if unclear6869## Framework-Specific Notes7071### Express/Node.js72- Check for route middleware that might affect auth/validation73- Look for request validators (Joi, express-validator, etc.)74- Extract JSDoc comments for endpoint descriptions7576### FastAPI77- FastAPI auto-generates OpenAPI docs, but this skill can enhance them78- Extract Pydantic models for request/response schemas79- Check for `response_model` and `status_code` parameters8081### NestJS82- Look for DTOs (Data Transfer Objects) for schemas83- Check for Swagger decorators (`@ApiOperation`, `@ApiResponse`)84- Extract metadata from controller and method decorators8586## Best Practices87881. **Use existing schemas**: If the codebase has TypeScript interfaces, Pydantic models, or similar, use them for accurate schemas892. **Include examples**: Add request/response examples from tests if available903. **Group logically**: Organize endpoints by resource or feature area using tags914. **Version appropriately**: Use the API version from the codebase (e.g., "1.0.0")925. **Add descriptions**: Use code comments/docstrings for endpoint descriptions9394## Supporting Files9596- `templates/openapi-3.0.yaml`: Base OpenAPI template97- `examples.md`: Framework-specific examples