Skip to content

huangjia2019/claude-code-engineering / 04-Skills/projects/06-agent-skill-combo/.claude/skills/api-generating

api-generating

Verified

Generate API endpoint documentation from Express route files. Use when the user asks to generate, update, or review API docs for Express.js routes.

FileKindSize
SKILL.mdskill md1.7 KB
scripts/detect-routes.pyscript4.4 KB
templates/api-doc.mdmarkdown1018 B

scripts/detect-routes.py

View on GitHub
#!/usr/bin/env python3
"""
Express.js Route Detector
=========================
Scans a directory for Express route definitions and outputs a structured list.

Handles edge cases that simple Grep cannot:
- router.use() mounted sub-routers with prefix
- Dynamic route parameters (:id, :slug)
- Re-exported routers (module.exports = router)
- Chained methods (router.route('/path').get().post())

Usage:
    python detect-routes.py <src_directory>

Output format (one route per line):
    METHOD  /full/path  source_file:line_number
"""

import os
import re
import sys


# Patterns for Express route definitions
ROUTE_PATTERNS = [
    # router.get('/path', handler)  or  app.get('/path', handler)
    re.compile(
        r'(?:router|app)\.(get|post|put|patch|delete|all)\s*\(\s*[\'"]([^\'"]+)[\'"]',
        re.IGNORECASE,
    ),
    # router.route('/path').get().post()
    re.compile(
        r'(?:router|app)\.route\s*\(\s*[\'"]([^\'"]+)[\'"]',
        re.IGNORECASE,
    ),
]

# Pattern for sub-router mounting: app.use('/prefix', someRouter)
MOUNT_PATTERN = re.compile(
    r'(?:app|router)\.use\s*\(\s*[\'"]([^\'"]+)[\'"]\s*,\s*(\w+)',
)

# Pattern for chained methods on route()
CHAINED_METHOD = re.compile(
    r'\.(get|post|put|patch|delete)\s*\(',
    re.IGNORECASE,
)


def scan_file(filepath):
    """Scan a single file for route definitions."""
    routes = []
    try:
        with open(filepath, 'r', encoding='utf-8') as f:
            lines = f.readlines()
    except (UnicodeDecodeError, PermissionError):
        return routes

    for i, line in enumerate(lines, 1):
        # Check standard route patterns
        for pattern in ROUTE_PATTERNS:
            for match in pattern.finditer(line):
                groups = match.groups()
                if len(groups) == 2:
                    # Standard route: (method, path)
                    method, path = groups
                    routes.append({
                        'method': method.upper(),
                        'path': path,
                        'file': filepath,
                        'line': i,
                    })
                elif len(groups) == 1:
                    # router.route() — need to find chained methods
                    route_path = groups[0]
                    # Look at this line and next few lines for chained methods
                    context = ''.join(lines[i-1:min(i+15, len(lines))])
                    for chain_match in CHAINED_METHOD.finditer(context):
                        routes.append({
                            'method': chain_match.group(1).upper(),
                            'path': route_path,
                            'file': filepath,
                            'line': i,
                        })

    return routes


def find_mount_prefixes(entry_file):
    """Find sub-router mount points in the main app file."""
    prefixes = {}
    try:
        with open(entry_file, 'r', encoding='utf-8') as f:
            content = f.read()
        for match in MOUNT_PATTERN.finditer(content):
            prefix, router_var = match.groups()
            prefixes[router_var] = prefix
    except (FileNotFoundError, UnicodeDecodeError):
        pass
    return prefixes


def scan_directory(src_dir):
    """Recursively scan directory for route files."""
    all_routes = []

    for root, _dirs, files in os.walk(src_dir):
        for filename in files:
            if filename.endswith(('.js', '.ts', '.mjs')):
                filepath = os.path.join(root, filename)
                routes = scan_file(filepath)
                all_routes.extend(routes)

    return all_routes


def main():
    if len(sys.argv) < 2:
        print("Usage: python detect-routes.py <src_directory>", file=sys.stderr)
        sys.exit(1)

    src_dir = sys.argv[1]

    if not os.path.isdir(src_dir):
        print(f"Error: {src_dir} is not a directory", file=sys.stderr)
        sys.exit(1)

    routes = scan_directory(src_dir)

    if not routes:
        print("No routes found.", file=sys.stderr)
        sys.exit(0)

    # Output header
    print(f"{'METHOD':<8} {'PATH':<40} {'SOURCE'}")
    print("-" * 80)

    # Sort by path then method
    routes.sort(key=lambda r: (r['path'], r['method']))

    for route in routes:
        rel_path = os.path.relpath(route['file'], src_dir)
        source = f"{rel_path}:{route['line']}"
        print(f"{route['method']:<8} {route['path']:<40} {source}")

    print(f"\nTotal: {len(routes)} routes found")


if __name__ == '__main__':
    main()
rea-changelog-updatemorluto/reaPrepare or rewrite REA release changelogs and GitHub release notes from pinned Git history, with verified contributor thanks and Release Please synchronization.Stars: 469kUpdated Claude CodeCodexVerifiedInstall
academy-guideanthropics/skillsStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.Stars: 197kUpdated Claude CodeCodexVerifiedInstall
claude-apianthropics/skillsReference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER — read BEFORE opening the target file; don't skip because it "looks like a one-liner" — whenever: the prompt names Claude/Anthropic in any form (Claude, Anthropic, Fable, Opus, Sonnet, Haiku, `anthropic`, `@anthropic-ai`, `claude-*`, `us.anthropic.*`, `[1m]`); the user asks about an LLM (pricing/model choice/limits/caching) — never answer from memory; OR the task is LLM-shaped with provider unstated (agent/MCP/tool-definition/multi-agent/RAG/LLM-judge/computer-use; generate/summarize/extract/classify/rewrite/converse over NL; debugging refusals/cutoffs/streaming/tool-calls/tokens). SKIP only when another provider is being worked on (overrides all triggers): OpenAI/GPT/Gemini/Llama/Mistral/Cohere/Ollama named in the query; OR `grep -rE 'openai|langchain_openai|google.generativeai|genai|mistralai|cohere|ollama'` over the project hits (run this grep FIRST if no provider named — don't Read the file).Stars: 197kUpdated Claude CodeCodexUnverifiedInstall
doc-coauthoringanthropics/skillsGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.Stars: 197kUpdated Claude CodeCodexVerifiedInstall