Generate comprehensive, developer-friendly API documentation from code, including endpoints, parameters, examples, and best practices
Add this skill
npx mdskills install sickn33/api-documentation-generatorComprehensive documentation guide with excellent examples and best practices throughout
1---2name: api-documentation-generator3description: "Generate comprehensive, developer-friendly API documentation from code, including endpoints, parameters, examples, and best practices"4---56# API Documentation Generator78## Overview910Automatically generate clear, comprehensive API documentation from your codebase. This skill helps you create professional documentation that includes endpoint descriptions, request/response examples, authentication details, error handling, and usage guidelines.1112Perfect for REST APIs, GraphQL APIs, and WebSocket APIs.1314## When to Use This Skill1516- Use when you need to document a new API17- Use when updating existing API documentation18- Use when your API lacks clear documentation19- Use when onboarding new developers to your API20- Use when preparing API documentation for external users21- Use when creating OpenAPI/Swagger specifications2223## How It Works2425### Step 1: Analyze the API Structure2627First, I'll examine your API codebase to understand:28- Available endpoints and routes29- HTTP methods (GET, POST, PUT, DELETE, etc.)30- Request parameters and body structure31- Response formats and status codes32- Authentication and authorization requirements33- Error handling patterns3435### Step 2: Generate Endpoint Documentation3637For each endpoint, I'll create documentation including:3839**Endpoint Details:**40- HTTP method and URL path41- Brief description of what it does42- Authentication requirements43- Rate limiting information (if applicable)4445**Request Specification:**46- Path parameters47- Query parameters48- Request headers49- Request body schema (with types and validation rules)5051**Response Specification:**52- Success response (status code + body structure)53- Error responses (all possible error codes)54- Response headers5556**Code Examples:**57- cURL command58- JavaScript/TypeScript (fetch/axios)59- Python (requests)60- Other languages as needed6162### Step 3: Add Usage Guidelines6364I'll include:65- Getting started guide66- Authentication setup67- Common use cases68- Best practices69- Rate limiting details70- Pagination patterns71- Filtering and sorting options7273### Step 4: Document Error Handling7475Clear error documentation including:76- All possible error codes77- Error message formats78- Troubleshooting guide79- Common error scenarios and solutions8081### Step 5: Create Interactive Examples8283Where possible, I'll provide:84- Postman collection85- OpenAPI/Swagger specification86- Interactive code examples87- Sample responses8889## Examples9091### Example 1: REST API Endpoint Documentation9293```markdown94## Create User9596Creates a new user account.9798**Endpoint:** `POST /api/v1/users`99100**Authentication:** Required (Bearer token)101102**Request Body:**103\`\`\`json104{105 "email": "user@example.com", // Required: Valid email address106 "password": "SecurePass123!", // Required: Min 8 chars, 1 uppercase, 1 number107 "name": "John Doe", // Required: 2-50 characters108 "role": "user" // Optional: "user" or "admin" (default: "user")109}110\`\`\`111112**Success Response (201 Created):**113\`\`\`json114{115 "id": "usr_1234567890",116 "email": "user@example.com",117 "name": "John Doe",118 "role": "user",119 "createdAt": "2026-01-20T10:30:00Z",120 "emailVerified": false121}122\`\`\`123124**Error Responses:**125126- `400 Bad Request` - Invalid input data127 \`\`\`json128 {129 "error": "VALIDATION_ERROR",130 "message": "Invalid email format",131 "field": "email"132 }133 \`\`\`134135- `409 Conflict` - Email already exists136 \`\`\`json137 {138 "error": "EMAIL_EXISTS",139 "message": "An account with this email already exists"140 }141 \`\`\`142143- `401 Unauthorized` - Missing or invalid authentication token144145**Example Request (cURL):**146\`\`\`bash147curl -X POST https://api.example.com/api/v1/users \148 -H "Authorization: Bearer YOUR_TOKEN" \149 -H "Content-Type: application/json" \150 -d '{151 "email": "user@example.com",152 "password": "SecurePass123!",153 "name": "John Doe"154 }'155\`\`\`156157**Example Request (JavaScript):**158\`\`\`javascript159const response = await fetch('https://api.example.com/api/v1/users', {160 method: 'POST',161 headers: {162 'Authorization': `Bearer ${token}`,163 'Content-Type': 'application/json'164 },165 body: JSON.stringify({166 email: 'user@example.com',167 password: 'SecurePass123!',168 name: 'John Doe'169 })170});171172const user = await response.json();173console.log(user);174\`\`\`175176**Example Request (Python):**177\`\`\`python178import requests179180response = requests.post(181 'https://api.example.com/api/v1/users',182 headers={183 'Authorization': f'Bearer {token}',184 'Content-Type': 'application/json'185 },186 json={187 'email': 'user@example.com',188 'password': 'SecurePass123!',189 'name': 'John Doe'190 }191)192193user = response.json()194print(user)195\`\`\`196```197198### Example 2: GraphQL API Documentation199200```markdown201## User Query202203Fetch user information by ID.204205**Query:**206\`\`\`graphql207query GetUser($id: ID!) {208 user(id: $id) {209 id210 email211 name212 role213 createdAt214 posts {215 id216 title217 publishedAt218 }219 }220}221\`\`\`222223**Variables:**224\`\`\`json225{226 "id": "usr_1234567890"227}228\`\`\`229230**Response:**231\`\`\`json232{233 "data": {234 "user": {235 "id": "usr_1234567890",236 "email": "user@example.com",237 "name": "John Doe",238 "role": "user",239 "createdAt": "2026-01-20T10:30:00Z",240 "posts": [241 {242 "id": "post_123",243 "title": "My First Post",244 "publishedAt": "2026-01-21T14:00:00Z"245 }246 ]247 }248 }249}250\`\`\`251252**Errors:**253\`\`\`json254{255 "errors": [256 {257 "message": "User not found",258 "extensions": {259 "code": "USER_NOT_FOUND",260 "userId": "usr_1234567890"261 }262 }263 ]264}265\`\`\`266```267268### Example 3: Authentication Documentation269270```markdown271## Authentication272273All API requests require authentication using Bearer tokens.274275### Getting a Token276277**Endpoint:** `POST /api/v1/auth/login`278279**Request:**280\`\`\`json281{282 "email": "user@example.com",283 "password": "your-password"284}285\`\`\`286287**Response:**288\`\`\`json289{290 "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",291 "expiresIn": 3600,292 "refreshToken": "refresh_token_here"293}294\`\`\`295296### Using the Token297298Include the token in the Authorization header:299300\`\`\`301Authorization: Bearer YOUR_TOKEN302\`\`\`303304### Token Expiration305306Tokens expire after 1 hour. Use the refresh token to get a new access token:307308**Endpoint:** `POST /api/v1/auth/refresh`309310**Request:**311\`\`\`json312{313 "refreshToken": "refresh_token_here"314}315\`\`\`316```317318## Best Practices319320### ✅ Do This321322- **Be Consistent** - Use the same format for all endpoints323- **Include Examples** - Provide working code examples in multiple languages324- **Document Errors** - List all possible error codes and their meanings325- **Show Real Data** - Use realistic example data, not "foo" and "bar"326- **Explain Parameters** - Describe what each parameter does and its constraints327- **Version Your API** - Include version numbers in URLs (/api/v1/)328- **Add Timestamps** - Show when documentation was last updated329- **Link Related Endpoints** - Help users discover related functionality330- **Include Rate Limits** - Document any rate limiting policies331- **Provide Postman Collection** - Make it easy to test your API332333### ❌ Don't Do This334335- **Don't Skip Error Cases** - Users need to know what can go wrong336- **Don't Use Vague Descriptions** - "Gets data" is not helpful337- **Don't Forget Authentication** - Always document auth requirements338- **Don't Ignore Edge Cases** - Document pagination, filtering, sorting339- **Don't Leave Examples Broken** - Test all code examples340- **Don't Use Outdated Info** - Keep documentation in sync with code341- **Don't Overcomplicate** - Keep it simple and scannable342- **Don't Forget Response Headers** - Document important headers343344## Documentation Structure345346### Recommended Sections3473481. **Introduction**349 - What the API does350 - Base URL351 - API version352 - Support contact3533542. **Authentication**355 - How to authenticate356 - Token management357 - Security best practices3583593. **Quick Start**360 - Simple example to get started361 - Common use case walkthrough3623634. **Endpoints**364 - Organized by resource365 - Full details for each endpoint3663675. **Data Models**368 - Schema definitions369 - Field descriptions370 - Validation rules3713726. **Error Handling**373 - Error code reference374 - Error response format375 - Troubleshooting guide3763777. **Rate Limiting**378 - Limits and quotas379 - Headers to check380 - Handling rate limit errors3813828. **Changelog**383 - API version history384 - Breaking changes385 - Deprecation notices3863879. **SDKs and Tools**388 - Official client libraries389 - Postman collection390 - OpenAPI specification391392## Common Pitfalls393394### Problem: Documentation Gets Out of Sync395**Symptoms:** Examples don't work, parameters are wrong, endpoints return different data396**Solution:**397- Generate docs from code comments/annotations398- Use tools like Swagger/OpenAPI399- Add API tests that validate documentation400- Review docs with every API change401402### Problem: Missing Error Documentation403**Symptoms:** Users don't know how to handle errors, support tickets increase404**Solution:**405- Document every possible error code406- Provide clear error messages407- Include troubleshooting steps408- Show example error responses409410### Problem: Examples Don't Work411**Symptoms:** Users can't get started, frustration increases412**Solution:**413- Test every code example414- Use real, working endpoints415- Include complete examples (not fragments)416- Provide a sandbox environment417418### Problem: Unclear Parameter Requirements419**Symptoms:** Users send invalid requests, validation errors420**Solution:**421- Mark required vs optional clearly422- Document data types and formats423- Show validation rules424- Provide example values425426## Tools and Formats427428### OpenAPI/Swagger429Generate interactive documentation:430```yaml431openapi: 3.0.0432info:433 title: My API434 version: 1.0.0435paths:436 /users:437 post:438 summary: Create a new user439 requestBody:440 required: true441 content:442 application/json:443 schema:444 $ref: '#/components/schemas/CreateUserRequest'445```446447### Postman Collection448Export collection for easy testing:449```json450{451 "info": {452 "name": "My API",453 "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"454 },455 "item": [456 {457 "name": "Create User",458 "request": {459 "method": "POST",460 "url": "{{baseUrl}}/api/v1/users"461 }462 }463 ]464}465```466467## Related Skills468469- `@doc-coauthoring` - For collaborative documentation writing470- `@copywriting` - For clear, user-friendly descriptions471- `@test-driven-development` - For ensuring API behavior matches docs472- `@systematic-debugging` - For troubleshooting API issues473474## Additional Resources475476- [OpenAPI Specification](https://swagger.io/specification/)477- [REST API Best Practices](https://restfulapi.net/)478- [GraphQL Documentation](https://graphql.org/learn/)479- [API Design Patterns](https://www.apiguide.com/)480- [Postman Documentation](https://learning.postman.com/docs/)481482---483484**Pro Tip:** Keep your API documentation as close to your code as possible. Use tools that generate docs from code comments to ensure they stay in sync!485
Full transparency — inspect the skill content before installing.