skillZs
LIVE SKILL TAGS
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
REAL INSTALL DATA
← back to all skills
wu529778790/shenzjd-skills341 installs

api-doc-generator

Use when generating OpenAPI/Swagger API docs from existing code — scans routes/annotations, extracts params and responses, outputs a YAML/JSON spec.

How do I install this agent skill?

npx skills add https://github.com/wu529778790/shenzjd-skills --skill api-doc-generator
view source ↗

Is this agent skill safe to install?

  • Gen Agent Trust Hubpass

    The API Doc Generator skill appears to be a legitimate utility for scanning project source code to generate OpenAPI/Swagger documentation. It uses standard command-line tools and a well-known documentation CLI for previewing results.

  • Socketpass

    No alerts

  • Snykfail

    Risk: CRITICAL · 1 issue

What does this agent skill do?

API Doc Generator

从代码自动生成 API 文档,支持 OpenAPI/Swagger 规范。

Overview

扫描项目代码中的路由和接口定义,自动提取参数、返回值、注释,生成符合 OpenAPI 3.0 规范的 YAML 文件和可交互的文档页面。

When to Use

  • User wants to generate API documentation
  • User mentions OpenAPI, Swagger, or API docs
  • User has REST/GraphQL endpoints that need documentation
  • User says "生成 API 文档" / "create API docs"
  • User inputs /api-doc-generator

When NOT to Use:

  • User only wants to write API descriptions in README
  • User wants to test APIs (use testing tools)
  • User's project has no HTTP endpoints
  • User wants to generate SDK/client code
  • User wants to mock APIs (use Mockoon, WireMock)

Core Pattern

Step 1: 检测框架和路由

框架检测方式路由提取
Express/Koa/Fastifyrequire('express') / 路由文件扫描 app.get/post/put/delete
Next.js API Routesapp/api/ 目录扫描 route.ts 文件
Gin (Go)r.GET/POST扫描 router 注册
Flask/FastAPI (Python)@app.route / @router扫描装饰器
Spring Boot (Java)@GetMapping / @RestController扫描注解
# 快速检测
grep -rE "app\.(get|post|put|delete|patch)" --include="*.ts" --include="*.js" --include="*.go" --include="*.py" -l

Step 2: 提取接口信息

对每个路由提取:

  • HTTP Method + Path
  • 请求参数:query、params、body(从类型定义/JSDoc/注解推断)
  • 响应格式:从 return 语句或类型定义推断
  • 注释/描述:从代码注释提取
  • 认证要求:检查是否有 auth middleware

Step 3: 生成 OpenAPI YAML

使用 templates/openapi.yaml(Handlebars 模板,含 {{variable}}{{#each}} 占位符)作为基础。将提取的接口信息注入对应变量,渲染后输出 openapi.yaml。渲染结果大致如下:

openapi: 3.0.3
info:
  title: 项目名 API
  version: 1.0.0
paths:
  /api/users:
    get:
      summary: 获取用户列表
      parameters: [...]
      responses:
        '200':
          description: 成功
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/User'

Step 4: 生成交互式文档页面(可选)

使用 Swagger UI 或 Redoc 生成可浏览的 HTML 页面:

# 使用 npx 快速预览
npx @redocly/cli preview-docs openapi.yaml

Quick Reference

/api-doc-generator                    # 扫描当前项目,生成 openapi.yaml
/api-doc-generator --format yaml      # 输出 YAML(默认)
/api-doc-generator --format json      # 输出 JSON
/api-doc-generator --preview          # 生成并预览交互式文档
参数说明默认值
--format输出格式 yaml / jsonyaml
--preview生成交互式 HTML 文档false

Common Mistakes

错误正确做法原因
只扫描一个文件递归扫描所有路由文件可能遗漏接口
硬编码请求体结构从类型定义推断保持文档与代码一致
不处理嵌套路由分析路由注册的完整路径/api/users/:id:id 需要标注
忽略错误响应添加 4xx/5xx 响应完整的 API 文档需要错误说明
忽略认证要求检查 auth middleware客户端需要知道哪些接口需要认证

Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.

<a href="https://skillzs.dev/skills/wu529778790/shenzjd-skills/api-doc-generator">View api-doc-generator on skillZs</a>