Agent Skillszebbern/claude-code-guide › route-to-openapi

route-to-openapi

GitHub

自动扫描代码中的路由定义,生成符合 OpenAPI 3.0.3 规范的 RESTful API 文档。支持 Flask、FastAPI、Express、Gin 等主流框架,提取路径、参数及响应模型,便于导入 Swagger UI 或 Redoc。

skills/route-to-openapi/SKILL.md zebbern/claude-code-guide

触发场景

用户询问如何生成 API 文档 需要导出 OpenAPI 或 Swagger 规范 从代码中提取接口端点信息

安装

npx skills add zebbern/claude-code-guide --skill route-to-openapi -g -y
更多选项

不安装直接使用

npx skills use zebbern/claude-code-guide@route-to-openapi

指定 Agent (Claude Code)

npx skills add zebbern/claude-code-guide --skill route-to-openapi -a claude-code -g -y

安装 repo 全部 skill

npx skills add zebbern/claude-code-guide --all -g -y

预览 repo 内 skill

npx skills add zebbern/claude-code-guide --list

SKILL.md

Frontmatter
{
    "name": "route-to-openapi",
    "license": "MIT",
    "description": "Generates RESTful API documentation (OpenAPI 3.0 \/ Swagger spec) by scanning route definitions in code for Flask, FastAPI, Express, Gin, and other frameworks. Trigger when users ask about API documentation, OpenAPI, Swagger, endpoint docs, generating docs from code, or extracting endpoints."
}

route-to-openapi

Automatically scan route/endpoint definitions in source code and generate RESTful API documentation conforming to the OpenAPI 3.0.3 specification.

Supports major web frameworks with automatic framework detection. Extracts HTTP methods, paths, parameters, request bodies, response models, and doc comments, then outputs a standard OpenAPI spec file ready to import into Swagger UI or Redoc.

Quick Start

# Scan source directory, output OpenAPI spec in JSON format
python scripts/generate_api_doc.py ./src

# Specify output format and file
python scripts/generate_api_doc.py ./src --format yaml --output api-spec.yaml

# Specify framework and API metadata
python scripts/generate_api_doc.py ./app --framework flask --title "My API" --version 2.0.0

# Add server URLs
python scripts/generate_api_doc.py ./routes --server http://localhost:3000 --server https://api.example.com

Supported Frameworks

Language Framework Parsing Method
Python Flask AST parsing (decorators + type annotations + docstrings)
Python FastAPI AST parsing (decorators + Pydantic models + type annotations)
Python Django REST Framework AST parsing (@api_view decorators)
JavaScript/TypeScript Express.js Regex matching (app.get() / router.get() + JSDoc)
Go Gin Regex matching (r.GET() / group.GET() + comments)
Go Echo Regex matching (e.GET() + comments)

Extraction Capabilities

The script automatically extracts the following information:

  • HTTP Methods: GET / POST / PUT / DELETE / PATCH, etc.
  • Route Paths: Automatically converts each framework's path parameter format to the OpenAPI {param} format
  • Path Parameters: Extracted from route patterns (with type inference)
  • Query Parameters: Extracted from function signatures (Python frameworks)
  • Request Bodies: Inferred from type annotations and Pydantic models (FastAPI)
  • Response Models: Extracted from the response_model parameter (FastAPI)
  • Endpoint Descriptions: Extracted from docstrings / JSDoc / inline comments
  • Tag Grouping: Automatically grouped by source file module name

Path Parameter Format Conversion

Framework Source Format Converted Result
Flask <int:user_id> {user_id} (type: integer)
FastAPI {user_id} {user_id} (unchanged)
Express :user_id {user_id}
Gin/Echo :user_id {user_id}

Parameters

Parameter Description Default
source_dir Source directory to scan (required) -
-f, --format Output format: json or yaml json
-o, --output Output file path stdout
--framework Force a specific framework (skip auto-detection) Auto-detect
--title API documentation title API Documentation
--version API version number 1.0.0
--description API description text Empty
--server Server URL (can be specified multiple times) None

Output Example

{
  "openapi": "3.0.3",
  "info": {
    "title": "My API",
    "version": "1.0.0"
  },
  "paths": {
    "/users": {
      "get": {
        "summary": "List all users",
        "operationId": "list_users",
        "tags": ["users"],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": { "description": "Successful response" }
        }
      }
    },
    "/users/{user_id}": {
      "get": {
        "summary": "Get user by ID",
        "operationId": "get_user",
        "tags": ["users"],
        "parameters": [
          {
            "name": "user_id",
            "in": "path",
            "required": true,
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": { "description": "Successful response" }
        }
      }
    }
  }
}

Prerequisites

  • Python 3.8+
  • No additional dependencies required — uses only the Python standard library
  • The scanned project must use one of the supported web frameworks listed above

版本历史

  • 1ed99ef 当前 2026-07-25 05:53

同 Skill 集合

skills/academic-paper-reviewer/SKILL.md
skills/active-directory-attacks/SKILL.md
skills/api-fuzzing-bug-bounty/SKILL.md
skills/api-shape-explorer/SKILL.md
skills/audit-flow/SKILL.md
skills/authentication-patterns/SKILL.md
skills/aws-penetration-testing/SKILL.md
skills/broken-authentication/SKILL.md
skills/burp-suite-testing/SKILL.md
skills/caching/SKILL.md
skills/chart-image/SKILL.md
skills/cloud-penetration-testing/SKILL.md
skills/code-documenter/SKILL.md
skills/code-to-diagram/SKILL.md
skills/composition-patterns/SKILL.md
skills/cross-examine/SKILL.md
skills/cv-tailor/SKILL.md
skills/data-viz-renderer/SKILL.md
skills/database-optimizer/SKILL.md
skills/database-scout/SKILL.md
skills/dataset-quality-audit/SKILL.md
skills/deep-module-refactor/SKILL.md
skills/design-system-builder/SKILL.md
skills/dev-guide-generator/SKILL.md
skills/ethical-hacking-methodology/SKILL.md
skills/file-path-traversal/SKILL.md
skills/html-injection-testing/SKILL.md
skills/http-load-profiler/SKILL.md
skills/idor-testing/SKILL.md
skills/linux-privilege-escalation/SKILL.md
skills/linux-shell-scripting/SKILL.md
skills/localization-toolkit/SKILL.md
skills/log-error-digest/SKILL.md
skills/metasploit-framework/SKILL.md
skills/network-101/SKILL.md
skills/nextjs-developer/SKILL.md
skills/pdf/SKILL.md
skills/pentest-checklist/SKILL.md
skills/pentest-commands/SKILL.md
skills/pipeline-blueprint/SKILL.md
skills/playwright/ci/SKILL.md
skills/playwright/core/SKILL.md
skills/playwright/migration/SKILL.md
skills/playwright/playwright-cli/SKILL.md
skills/playwright/pom/SKILL.md
skills/playwright/SKILL.md
skills/privilege-escalation-methods/SKILL.md
skills/project-sizing-guide/SKILL.md
skills/r2-upload/SKILL.md
skills/r3f-animation/SKILL.md

元信息

文件数
0
版本
fd8a781
Hash
bd4da9fb
收录时间
2026-07-25 05:53

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-28 11:03
浙ICP备14020137号-1 $访客地图$