Generate API documentation from code
Generates comprehensive API documentation from codebase analysis and OpenAPI specifications.
/plugin marketplace add davepoon/buildwithclaude/plugin install all-commands@buildwithclaude1. **Code Analysis and Discovery**Generate API documentation from code
Follow this systematic approach to create API documentation: $ARGUMENTS
Code Analysis and Discovery
Documentation Tool Selection
API Specification Generation
For REST APIs with OpenAPI:
openapi: 3.0.0
info:
title: $ARGUMENTS API
version: 1.0.0
description: Comprehensive API for $ARGUMENTS
servers:
- url: https://api.example.com/v1
paths:
/users:
get:
summary: List users
parameters:
- name: page
in: query
schema:
type: integer
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
components:
schemas:
User:
type: object
properties:
id:
type: integer
name:
type: string
email:
type: string
Endpoint Documentation
Request/Response Examples
Authentication Documentation
Data Model Documentation
Error Handling Documentation
Interactive Documentation Setup
Swagger UI Integration:
<!DOCTYPE html>
<html>
<head>
<title>API Documentation</title>
<link rel="stylesheet" type="text/css" href="./swagger-ui-bundle.css" />
</head>
<body>
<div id="swagger-ui"></div>
<script src="./swagger-ui-bundle.js"></script>
<script>
SwaggerUIBundle({
url: './api-spec.yaml',
dom_id: '#swagger-ui'
});
</script>
</body>
</html>
Code Annotation and Comments
Automated Documentation Generation
For Node.js/Express:
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerUi = require('swagger-ui-express');
const options = {
definition: {
openapi: '3.0.0',
info: {
title: 'API Documentation',
version: '1.0.0',
},
},
apis: ['./routes/*.js'],
};
const specs = swaggerJsdoc(options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(specs));
Testing Integration
Version Management
Performance Documentation
SDK and Client Library Documentation
Environment-Specific Documentation
Security Documentation
Maintenance and Updates
Framework-Specific Examples:
FastAPI (Python):
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI(title="My API", version="1.0.0")
class User(BaseModel):
id: int
name: str
email: str
@app.get("/users/{user_id}", response_model=User)
async def get_user(user_id: int):
"""Get a user by ID."""
return {"id": user_id, "name": "John", "email": "john@example.com"}
Spring Boot (Java):
@RestController
@Api(tags = "Users")
public class UserController {
@GetMapping("/users/{id}")
@ApiOperation(value = "Get user by ID")
public ResponseEntity<User> getUser(
@PathVariable @ApiParam("User ID") Long id) {
// Implementation
}
}
Remember to keep documentation up-to-date with code changes and make it easily accessible to both internal teams and external consumers.