mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-07-25 11:40:52 +02:00
7db5ade777
Added comprehensive examples for Claude Code features including slash commands, subagents, memory, MCP protocol, skills, and plugins with documentation and quick reference guides. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import ast
|
|
import json
|
|
from typing import Dict, List
|
|
|
|
class APIDocExtractor(ast.NodeVisitor):
|
|
"""Extract API documentation from Python source code."""
|
|
|
|
def __init__(self):
|
|
self.endpoints = []
|
|
|
|
def visit_FunctionDef(self, node):
|
|
"""Extract function documentation."""
|
|
if node.name.startswith('get_') or node.name.startswith('post_'):
|
|
doc = ast.get_docstring(node)
|
|
endpoint = {
|
|
'name': node.name,
|
|
'docstring': doc,
|
|
'params': [arg.arg for arg in node.args.args],
|
|
'returns': self._extract_return_type(node)
|
|
}
|
|
self.endpoints.append(endpoint)
|
|
self.generic_visit(node)
|
|
|
|
def _extract_return_type(self, node):
|
|
"""Extract return type from function annotation."""
|
|
if node.returns:
|
|
return ast.unparse(node.returns)
|
|
return "Any"
|
|
|
|
def generate_markdown_docs(endpoints: List[Dict]) -> str:
|
|
"""Generate markdown documentation from endpoints."""
|
|
docs = "# API Documentation\n\n"
|
|
|
|
for endpoint in endpoints:
|
|
docs += f"## {endpoint['name']}\n\n"
|
|
docs += f"{endpoint['docstring']}\n\n"
|
|
docs += f"**Parameters**: {', '.join(endpoint['params'])}\n\n"
|
|
docs += f"**Returns**: {endpoint['returns']}\n\n"
|
|
docs += "---\n\n"
|
|
|
|
return docs
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
with open(sys.argv[1], 'r') as f:
|
|
tree = ast.parse(f.read())
|
|
|
|
extractor = APIDocExtractor()
|
|
extractor.visit(tree)
|
|
|
|
markdown = generate_markdown_docs(extractor.endpoints)
|
|
print(markdown)
|