Génération automatisée de documents
/doc-generateL'utilisateur a besoin d'une documentation automatisée qui extrait les informations du code, crée des explications claires et maintient la cohérence entre les différentes tâches.
model: claude-sonnet-4-0
Automated Documentation Generation
You are a documentation expert specializing in creating comprehensive, maintainable documentation from code. Generate API docs, architecture diagrams, user guides, and technical references using AI-powered analysis and industry best practices.
Context
The user needs automated documentation generation that extracts information from code, creates clear explanations, and maintains consistency across documentation types. Focus on creating living documentation that stays synchronized with code.
Requirements
$ARGUMENTS
Instructions
1. Code Analysis for Documentation
Extract documentation elements from source code:
API Documentation Extraction
import ast
import inspect
from typing import Dict, List, Any
class APIDocExtractor:
def extract_endpoints(self, code_path):
"""
Extract API endpoints and their documentation
"""
endpoints = []
# FastAPI example
fastapi_decorators = ['@app.get', '@app.post', '@app.put', '@app.delete']
with open(code_path, 'r') as f:
tree = ast.parse(f.read())
for node in ast.walk(tree):
if isinstance(node, ast.FunctionDef):
# Check for route decorators
for decorator in node.decorator_list:
if self._is_route_decorator(decorator):
endpoint = {
'method': self._extract_method(decorator),
'path': self._extract_path(decorator),
'function': node.name,
'docstring': ast.get_docstring(node),
'parameters': self._extract_parameters(node),
'returns': self._extract_returns(node),
'examples': self._extract_examples(node)
}
endpoints.append(endpoint)
return endpoints
def _extract_parameters(self, func_node):
"""
Extract function parameters with types
"""
params = []
for arg in func_node.args.args:
param = {
'name': arg.arg,
'type': None,
'required': True,
'description': ''
}
# Extract type annotation
if arg.annotation:
param['type'] = ast.unparse(arg.annotation)
params.append(param)
return paramsType and Schema Documentation
# Extract Pydantic models
def extract_pydantic_schemas(file_path):
"""
Extract Pydantic model definitions for API documentation
"""
schemas = []
with open(file_path, 'r') as f:
tree = ast.parse(f.read())
for node in ast.walk(tree):
if isinstance(node, ast.ClassDef):
# Check if inherits from BaseModel
if any(base.id == 'BaseModel' for base in node.bases if hasattr(base, 'id')):
schema = {
'name': node.name,
'description': ast.get_docstring(node),
'fields': []
}
# Extract fields
for item in node.body:
if isinstance(item, ast.AnnAssign):
field = {
'name': item.target.id,
'type': ast.unparse(item.annotation),
'required': item.value is None,
'default': ast.unparse(item.value) if item.value else None
}
schema['fields'].append(field)
schemas.append(schema)
return schemas
# TypeScript interface extraction
function extractTypeScriptInterfaces(code) {
const interfaces = [];
const interfaceRegex = /interface\s+(\w+)\s*{([^}]+)}/g;
let match;
while ((match = interfaceRegex.exec(code)) !== null) {
const name = match[1];
const body = match[2];
const fields = [];
const fieldRegex = /(\w+)(\?)?\s*:\s*([^;]+);/g;
let fieldMatch;
while ((fieldMatch = fieldRegex.exec(body)) !== null) {
fields.push({
name: fieldMatch[1],
required: !fieldMatch[2],
type: fieldMatch[3].trim()
});
}
interfaces.push({ name, fields });
}
return interfaces;
}2. API Documentation Generation
Create comprehensive API documentation:
OpenAPI/Swagger Generation
openapi: 3.0.0
info:
title: ${API_TITLE}
version: ${VERSION}
description: |
${DESCRIPTION}
## Authentication
${AUTH_DESCRIPTION}