一键导入
documentation-generator
Auto-generate technical documentation, README files, and API documentation for software projects.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Auto-generate technical documentation, README files, and API documentation for software projects.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
PersonalOS skill: account-management
API endpoint testing, mocking, and integration testing for robust API development.
Optimize images, icons, and design assets for performance, quality, and developer handoff
Plan, track, and optimize budgets to maximize value and financial performance
CI/CD pipeline optimization, build failures, and deployment automation for DevOps workflows.
Code quality improvement, technical debt reduction, and refactoring patterns for maintainable software.
| name | documentation-generator |
| description | Auto-generate technical documentation, README files, and API documentation for software projects. |
Automated generation of technical documentation, README files, API documentation, and code comments.
Guides you through generating high-quality documentation automatically from code, tests, and specifications.
Documentation Types:
Assessment Checklist:
✓ What needs documentation? (API, code, setup)
✓ Who is the audience? (Users, developers, contributors)
✓ What are the key features to document?
✓ What examples should be included?
✓ What installation/setup steps are needed?
Sources for Documentation:
Extraction Techniques:
# Extract from code
import ast
import inspect
def extract_docstrings(module):
"""Extract all docstrings from a module"""
tree = ast.parse(inspect.getsource(module))
docstrings = []
for node in ast.walk(tree):
if isinstance(node, (ast.FunctionDef, ast.ClassDef)):
docstrings.append({
'name': node.name,
'docstring': ast.get_docstring(node)
})
return docstrings
# Extract from tests
def extract_test_examples(test_file):
"""Extract usage examples from tests"""
examples = []
# Parse test file for usage patterns
# Extract assertions as expected behavior
return examples
README Generator:
def generate_readme(project_info):
"""Generate README from project metadata"""
readme = f"""# {project_info['name']}
{project_info['description']}
## Installation
{project_info['installation']}
## Usage
{project_info['usage']}
## API
{project_info['api_docs']}
## Examples
{project_info['examples']}
## License
{project_info['license']}
"""
return readme
API Documentation Generator:
def generate_api_docs(openapi_spec):
"""Generate API documentation from OpenAPI spec"""
docs = "# API Documentation\n\n"
for path, methods in openapi_spec['paths'].items():
docs += f"## {path}\n\n"
for method, details in methods.items():
docs += f"### {method.upper()}\n\n"
docs += f"{details.get('summary', '')}\n\n"
docs += "**Parameters:**\n"
for param in details.get('parameters', []):
docs += f"- `{param['name']}`: {param.get('description', '')}\n"
docs += "\n**Response:**\n"
for status, response in details.get('responses', {}).items():
docs += f"- {status}: {response.get('description', '')}\n"
return docs
Documentation Review Checklist:
✓ All documented features are accurate
✓ Examples work correctly
✓ Installation steps are complete
✓ API documentation matches actual API
✓ Code comments are up to date
✓ Spelling and grammar checked
✓ Formatting is consistent
✓ Links and references work
Maintenance Strategy:
Check if documentation matches code:
def check_documentation_drift():
"""Check if documentation matches current code"""
doc_strings = extract_docstrings(module)
actual_functions = extract_function_signatures(module)
missing_docs = set(actual_functions.keys()) - set(doc_strings.keys())
if missing_docs:
print(f"Missing documentation for: {missing_docs}")
return False
return True
CI/CD Integration:
# GitHub Actions
name: Generate Documentation
on: [push]
jobs:
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Generate docs
run: |
python generate_docs.py
- name: Deploy docs
run: |
git push origin gh-pages
Works With:
Jupyter Notebooks for Examples:
# Convert Jupyter notebook to Markdown
import nbformat
from nbconvert import MarkdownExporter
def notebook_to_markdown(notebook_path):
"""Convert Jupyter notebook to Markdown"""
with open(notebook_path) as f:
notebook = nbformat.read(f, as_version=4)
exporter = MarkdownExporter()
body, resources = exporter.from_notebook_node(notebook)
return body
Live API Documentation:
# Using Swagger UI with FastAPI
from fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
app = FastAPI()
@app.get("/users/{user_id}")
async def get_user(user_id: int):
return {"user_id": user_id, "name": "Test User"}
# Auto-generate interactive API docs at /docs
# http://localhost:8000/docs
Generate Architecture Diagrams:
# Generate architecture diagrams from code structure
def generate_architecture_diagram(project_structure):
"""Generate Mermaid diagram from project structure"""
diagram = "graph TD\n"
for module, dependencies in project_structure.items():
for dep in dependencies:
diagram += f" {module} --> {dep}\n"
return diagram
# Convert Mermaid to PNG/Diagram
# Use tools like Mermaid CLI or GitHub's native Mermaid support
Generate Design Documents:
def generate_design_doc(component_info):
"""Generate design document from component"""
doc = f"""# Design Document: {component_info['name']}
## Overview
{component_info['overview']}
## Architecture
```mermaid
{component_info['architecture_diagram']}
{component_info['components']}
{component_info['data_flow']}
{component_info['api']}
{component_info['dependencies']}
{component_info['testing']}
{component_info['improvements']} """ return doc
#### 3. Version-Specific Documentation
**Multi-Version Documentation:**
```python
def generate_versioned_docs(version):
"""Generate documentation for specific version"""
docs = {
'version': version,
'readme': generate_readme_for_version(version),
'api': generate_api_docs_for_version(version),
'changelog': generate_changelog_for_version(version)
}
return docs
# Generate for multiple versions
versions = ['v1.0.0', 'v1.1.0', 'v2.0.0']
for version in versions:
docs = generate_versioned_docs(version)
save_docs(docs, f"docs/{version}")
Quality Metrics:
Calculate Metrics:
def calculate_documentation_metrics(project):
"""Calculate documentation quality metrics"""
code_elements = extract_code_elements(project)
documented_elements = extract_documented_elements(project)
coverage = len(documented_elements) / len(code_elements) * 100
accuracy = check_accuracy(project)
completeness = check_completeness(project)
return {
'coverage': coverage,
'accuracy': accuracy,
'completeness': completeness
}
Standard Templates:
# Template library
DOCUMENTATION_TEMPLATES = {
'api_endpoint': """
### {endpoint}
**Method:** {method}
**Description:** {description}
**Parameters:**
{parameters}
**Request Body:**
```json
{request_body}
Response:
{response_body}
Errors: {errors} """,
'module': """
{overview}
{functions}
{classes}
{examples} """ }
def generate_from_template(template_name, data): """Generate documentation from template""" template = DOCUMENTATION_TEMPLATES[template_name] return template.format(**data)
### Advanced Patterns
#### Pattern 1: Documentation-Driven Development
**DDD Workflow:**
#### Pattern 2: Automated Documentation Testing
**Test Documentation:**
```python
def test_documentation_examples():
"""Test all code examples in documentation"""
examples = extract_code_examples_from_docs()
for example in examples:
try:
exec(example['code'])
except Exception as e:
print(f"Example failed: {example['location']}")
print(f"Error: {e}")
assert False, "Documentation example doesn't work"
Build Search Index:
from whoosh.index import create_in, open_dir
from whoosh.fields import Schema, TEXT, ID
def create_doc_index():
"""Create search index for documentation"""
schema = Schema(
title=TEXT(stored=True),
content=TEXT,
path=ID(stored=True)
)
ix = create_in("doc_index", schema)
writer = ix.writer()
for doc_file in get_all_documentation():
doc = read_documentation(doc_file)
writer.add_document(
title=doc['title'],
content=doc['content'],
path=doc['path']
)
writer.commit()
Auto-Generate from Code:
import openai
def generate_docstring_from_code(function_code):
"""Generate docstring using AI"""
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{
"role": "user",
"content": f"""Generate a docstring for this function:
```python
{function_code}
Include:
Brief description
Parameters with types and descriptions
Return value description
Raises section if applicable
Example usage """ }] )
return response.choices[0].message.content
**Suggest Improvements:**
```python
def suggest_documentation_improvements(docs):
"""Use AI to suggest improvements"""
suggestions = []
for doc in docs:
analysis = analyze_documentation_quality(doc)
if analysis['score'] < 0.7:
suggestions.append({
'doc': doc['path'],
'issues': analysis['issues'],
'suggestions': generate_suggestions(doc)
})
return suggestions
Link Documentation Concepts:
def build_documentation_knowledge_graph(docs):
"""Build knowledge graph linking documentation concepts"""
graph = {
'nodes': [],
'edges': []
}
# Extract concepts
concepts = extract_concepts_from_docs(docs)
for concept in concepts:
graph['nodes'].append({
'id': concept['id'],
'label': concept['name'],
'type': concept['type']
})
# Link related concepts
relationships = find_relationships(concepts)
for rel in relationships:
graph['edges'].append({
'source': rel['from'],
'target': rel['to'],
'label': rel['type']
})
return graph
Identify Documentation Needs:
def predict_documentation_needs(code_changes):
"""Predict what documentation needs updating"""
needs = []
for change in code_changes:
# If new API endpoint added
if 'api' in change['path'] and 'endpoint' in change['diff']:
needs.append({
'type': 'api_documentation',
'path': change['path'],
'priority': 'high'
})
# If new feature added
if 'feature' in change['commit_message']:
needs.append({
'type': 'feature_documentation',
'feature': change['commit_message'],
'priority': 'medium'
})
return needs
Step-by-Step Tutorials:
def generate_interactive_tutorial(workflow):
"""Generate interactive tutorial from workflow"""
tutorial = f"""
# Tutorial: {workflow['title']}
{workflow['introduction']}
## Prerequisites
{workflow['prerequisites']}
## Step 1: {workflow['steps'][0]['title']}
{workflow['steps'][0]['content']}
```python
{workflow['steps'][0]['code']}
{workflow['steps'][1]['content']}
{workflow['steps'][1]['code']}
{workflow['next_steps']} """ return tutorial
#### 2. Video Documentation
**Generate Screenplay:**
```python
def generate_video_documentation_screenplay(features):
"""Generate screenplay for documentation video"""
screenplay = []
for feature in features:
screenplay.append({
'scene': f"Demo of {feature}",
'actions': [
"Show the feature in action",
"Explain the purpose",
"Show code example",
"Explain best practices"
],
'duration': '2:00'
})
return screenplay
Track Documentation Usage:
def track_documentation_analytics():
"""Track which documentation is most viewed"""
analytics = {
'page_views': get_page_views(),
'search_queries': get_search_queries(),
'bounce_rates': get_bounce_rates(),
'time_on_page': get_time_on_page(),
'user_feedback': get_user_feedback()
}
# Identify gaps
gaps = identify_documentation_gaps(analytics)
return analytics, gaps
Do:
Don't:
def generate_auto_readme(project_path):
"""Generate README from project structure"""
project_info = {
'name': get_project_name(project_path),
'description': get_description_from_package_json(project_path),
'installation': generate_installation_instructions(project_path),
'usage': generate_usage_examples(project_path),
'api': extract_api_documentation(project_path),
'examples': extract_test_examples(project_path),
'license': get_license(project_path)
}
readme = f"""# {project_info['name']}
{project_info['description']}
## Installation
{project_info['installation']}
## Usage
{project_info['usage']}
## API
{project_info['api']}
## Examples
{project_info['examples']}
## License
{project_info['license']}
"""
return readme
def extract_api_from_tests(test_file):
"""Extract API documentation from test file"""
api_docs = {}
with open(test_file) as f:
content = f.read()
# Extract endpoint tests
endpoint_tests = re.findall(r'def test_(\w+)\((.*?)\):', content)
for test_name, test_code in endpoint_tests:
# Extract endpoint and method
match = re.search(r'client\.(\w+)\([\'"](.+)[\'"]\)', test_code)
if match:
method, endpoint = match.groups()
api_docs[endpoint] = {
'method': method.upper(),
'test': test_name
}
return api_docs
def generate_changelog(git_log):
"""Generate changelog from git log"""
changelog = "# Changelog\n\n"
commits = parse_git_log(git_log)
for version in get_versions(commits):
changelog += f"## {version['tag']}\n\n"
changelog += f"Released: {version['date']}\n\n"
for category in ['Features', 'Bug Fixes', 'Breaking Changes']:
changelog += f"### {category}\n\n"
for commit in version['commits']:
if commit['type'] == category.lower():
changelog += f"- {commit['message']}\n"
changelog += "\n"
return changelog
Problem: Documentation doesn't match current code Fix: Auto-generate from code, check for drift regularly
Problem: Code examples in documentation don't run Fix: Test all examples, ensure they work
Problem: Either too detailed or not enough Fix: Write for target audience, provide multiple levels
Problem: Documentation outdated Fix: Auto-regenerate on code changes, version documentation
Problem: Documentation poorly organized Fix: Use consistent structure, add search, create index
A: Focus on essential information, use templates, generate multiple versions (brief vs. detailed), and use collapsible sections.
A: Auto-generate from code, use documentation testing, track drift, and integrate into CI/CD pipeline.
A: Both. Generate structure and API docs from code, write user guides and tutorials manually with input from AI.
A: Build search index, use proper keywords, tag concepts, and link related topics.
A: Cover all public APIs, key features, installation, and examples. Aim for comprehensive but not exhaustive.