api-documentation-generator
Generate comprehensive API documentation from repository sources including OpenAPI specs, code comments, docstrings, and existing documentation. Use when documenting APIs, creating API reference guides, or summarizing API functionality from codebases. Extracts endpoint details, request/response schemas, authentication methods, and generates code examples. Triggers when users ask to document APIs, generate API docs, create API reference, or summarize API endpoints from a repository.
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE /tmp/api-documentation-generator && cp -r /tmp/api-documentation-generator/skills/api-documentation-generator ~/.claude/skills/api-documentation-generatorSKILL.md
# API Documentation Generator
## Overview
Analyze a repository to extract and generate comprehensive API documentation, including endpoints, request/response schemas, authentication, and usage examples organized in a clear, multi-file structure.
## Workflow
### 1. Discover API Information Sources
Scan the repository to identify all sources of API information:
**Primary sources (in priority order):**
1. **OpenAPI/Swagger specifications** (`.yaml`, `.yml`, `.json`)
- Look in: root directory, `/docs`, `/api`, `/spec`, `/openapi`
- Files named: `openapi.yaml`, `swagger.json`, `api-spec.yaml`, etc.
2. **Code files with docstrings/comments**
- Python: Flask/FastAPI route decorators, docstrings
- JavaScript/TypeScript: Express routes, JSDoc comments
- Java: Spring annotations, Javadoc
- Go: HTTP handler comments
- Ruby: Rails routes, YARD comments
3. **Existing documentation**
- Markdown files in `/docs`, `/documentation`, `/api-docs`
- README files with API sections
- Wiki pages or doc site content
4. **Configuration files**
- `routes.rb`, `urls.py`, `routes.js`
- API gateway configurations
**Discovery approach:**
```bash
# Find OpenAPI specs
find . -name "openapi.*" -o -name "swagger.*" -o -name "*api-spec*"
# Find API route definitions
grep -r "@app.route\|@router\|app.get\|app.post" --include="*.py" --include="*.js"
# Find documentation
find . -path "*/docs/*" -name "*.md" -o -path "*/api/*" -name "*.md"
```
### 2. Extract API Information
Based on discovered sources, extract key information:
#### From OpenAPI Specs
Parse YAML/JSON to extract:
- Base URL and server information
- All paths and operations (GET, POST, PUT, PATCH, DELETE)
- Request parameters (path, query, header, body)
- Response schemas and status codes
- Authentication/security schemes
- Data models/schemas
- Tags and operation groupings
#### From Code Comments/Docstrings
Look for patterns like:
**Python (FastAPI/Flask):**
```python
@app.post("/users")
async def create_user(user: UserCreate):
"""
Create a new user.
Args:
user: User creation data
Returns:
Created user object
"""
```
**JavaScript (Express):**
```javascript
/**
* GET /users
* List all users
* @param {number} page - Page number
* @param {number} limit - Items per page
* @returns {Array<User>} List of users
*/
app.get('/users', (req, res) => { ... })
```
Extract:
- HTTP method and path
- Description from docstring/comment
- Parameters and types
- Return types
- Example usage if present
#### From Existing Documentation
Parse markdown files to extract:
- Endpoint descriptions
- Request/response examples
- Authentication details
- Rate limiting information
- Error codes
### 3. Organize Documentation Structure
Create a multi-file documentation structure organized by resource or API area:
```
docs/
├── README.md # Overview, authentication, getting started
├── endpoints/
│ ├── users.md # User-related endpoints
│ ├── products.md # Product-related endpoints
│ ├── orders.md # Order-related endpoints
│ └── ...
├── models/
│ └── schemas.md # Data models and schemas
├── errors.md # Error codes and handling
└── examples.md # Complete usage examples
```
**Grouping strategy:**
- Group by resource (users, products, orders)
- Group by OpenAPI tags if available
- Group by URL prefix if no tags
- Keep authentication, errors, and models separate
### 4. Generate Documentation Files
For each file, use the template from [assets/api-doc-template.md](assets/api-doc-template.md) as a guide.
#### README.md (Main Overview)
```markdown
# API Documentation
## Overview
[Brief description of the API and its purpose]
## Base URL
https://api.example.com/v1
## Authentication
[Describe auth method: Bearer tokens, API keys, OAuth2]
## Quick Start
[Simple example showing how to make first API call]
## Endpoints
- [Users](endpoints/users.md) - User management endpoints
- [Products](endpoints/products.md) - Product catalog endpoints
- [Orders](endpoints/orders.md) - Order processing endpoints
## Resources
- [Data Models](models/schemas.md) - Request/response schemas
- [Errors](errors.md) - Error codes and handling
- [Examples](examples.md) - Complete usage examples
## Rate Limiting
[Rate limit details if applicable]
## Versioning
[API versioning strategy if applicable]
```
#### Endpoint Files (e.g., `endpoints/users.md`)
For each endpoint, document:
**Endpoint header:**
```markdown
### POST /users
Create a new user account.
```
**Request details:**
```markdown
**Request:**
- **Method:** `POST`
- **Path:** `/users`
- **Headers:**
- `Content-Type: application/json`
- `Authorization: Bearer YOUR_TOKEN`
**Body:**
| Field | Type | Required | Description |
|-------|------|----------|-------------|
| name | string | Yes | User's full name |
| email | string | Yes | User's email address |
| role | string | No | User role (default: user) |
**Example:**
```json
{
"name": "John Doe",
"email": "john@example.com",
"role": "admin"
}
```
```
**Response details:**
```markdown
**Response:**
- **Status:** `201 Created`
- **Headers:**
- `Location: /users/123`
**Body:**
```json
{
"id": 123,
"name": "John Doe",
"email": "john@example.com",
"role": "admin",
"created_at": "2024-01-15T10:30:00Z"
}
```
**Error Responses:**
- `400 Bad Request` - Invalid input data
- `409 Conflict` - Email already exists
```
**Code examples:**
```markdown
**Example Request:**
```bash
curl -X POST "https://api.example.com/v1/users" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"name": "John Doe",
"email": "john@example.com"
}'
```
```python
import requests
response = requests.post(
"https://api.example.com/v1/users",
headers={"Authorization": "Bearer YOUR_TOKEN"},
json={
"name": "John Doe",
"email": "john@exApplies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.
Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.
Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.
Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.
Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.
CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
Detects and analyzes ambiguous language in software requirements and user stories. Use when reviewing requirements documents, user stories, specifications, or any software requirement text to identify vague quantifiers, unclear scope, undefined terms, missing edge cases, subjective language, and incomplete specifications. Provides detailed analysis with clarifying questions and suggested improvements.
Design and review APIs with suggestions for endpoints, parameters, return types, and best practices. Use when designing new APIs from requirements, reviewing existing API designs, generating API documentation, or getting implementation guidance. Supports REST APIs with focus on endpoint structure, request/response schemas, authentication, pagination, filtering, versioning, and OpenAPI specifications. Triggers when users ask to design, review, document, or improve APIs.