Token导航 LogoToken导航

Agent Skill · 开发

extract-openapi-from-code(从代码中提取 openapi)

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

extract-openapi-from-code 是开发类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为执行命令;许可证信息还不明确,第三方扫描已通过,按安装量在开发类的 21,746 个 Skill 里排第 21,583。

总安装 186周安装 8GitHub Stars 11下载 65核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:extract-openapi-from-code(从代码中提取 openapi)
来源仓库:https://github.com/speakeasy-api/agent-skills
仓库路径:skills/extract-openapi-from-code
安装命令:
npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-openapi-from-code
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-openapi-from-code

这个 Skill 是做什么的

开发类 Skill 面向写代码、改代码和排查问题,一般会读写仓库文件,部分还会执行构建或测试命令。

extract-openapi-from-code 用于辅助 API 设计和接口文档生成。适合梳理 endpoint、生成 OpenAPI 草稿或检查字段命名。使用时需确认真实业务语义和鉴权方式,避免凭空补字段。最好从现有代码或接口样例中提取事实生成文档。

适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

来源仓库内路径:skills/extract-openapi-from-code

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-ope…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要执行命令,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

extract-openapi-from-code 怎么安装?

在终端执行 npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-openapi-from-…。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

extract-openapi-from-code 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

extract-openapi-from-code 需要什么权限?

权限级别是执行命令。安装流程涉及命令执行,可能通过 npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-openapi-from-code 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

extract-openapi-from-code 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

extract-openapi-from-code 用的人多吗?

公开数据是累计安装 186 次,近一周安装 8 次,下载 65 次,GitHub 11 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

extract-openapi-from-code 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要执行命令,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理开发类任务、又不想每次都手写提示词的人。

不太适合

  • 不能接受 Skill 在你机器上执行命令的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

开发类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
skill-vetter

技能审查员 · OpenClaw

8,779,018986操作浏览器MIT-0通过
ontology

本体论 · OpenClaw

6,636,960576只读MIT-0通过
entra-app-registration

内部应用程序注册 · Codex、Claude

6,631,872764接触敏感数据未明确通过
entra-app-registration

内部应用程序注册 · Codex、Claude

3,757,680201接触敏感数据未明确通过
nano-banana-pro

纳米香蕉专业版 · OpenClaw

3,526,898364接触敏感数据MIT-0有提醒
extract-openapi-from-code

从代码中提取 openapi · 本页

18611执行命令未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

extract-openapi-from-code

Extract an OpenAPI specification from an existing API codebase. Covers eight major frameworks across Python, Java, JavaScript/TypeScript, Ruby, and PHP.

Content Guides

Each guide provides detailed setup, schema definition, Speakeasy extensions, authentication, and troubleshooting for that framework.

When to Use

  • User has an existing API and wants to generate an OpenAPI spec from it
  • User wants to create an SDK from code that has no OpenAPI spec yet
  • User mentions a specific framework (FastAPI, Flask, Django, Spring Boot, NestJS, Hono, Rails, Laravel)
  • User says: "extract OpenAPI", "code first", "generate spec from code", "existing API code"

Inputs

InputRequiredDescription
FrameworkYesThe API framework in use (see Decision Framework)
Project pathYesRoot directory of the API project
Output pathNoWhere to write the spec (default: openapi.json or openapi.yaml)
Target languageNoSDK target language, if generating an SDK after extraction

Outputs

OutputDescription
OpenAPI specA JSON or YAML file describing the API
Validation reportLint results from speakeasy lint

Prerequisites

  • The API project must be buildable and its dependencies installed
  • For runtime extraction (FastAPI, Spring Boot, NestJS, Hono), the app must be importable or startable
  • speakeasy CLI installed for post-extraction validation and SDK generation

Decision Framework

Use this tree to determine the extraction method:

FrameworkLanguageMethodRequires Running Server?
FastAPIPythonBuilt-in exportNo
Flask (flask-smorest)PythonCLI commandNo
Django REST FrameworkPythondrf-spectacular CLINo
Spring Boot (springdoc)JavaHTTP endpointYes
NestJSTypeScriptHTTP endpoint or scriptYes
Hono (zod-openapi)TypeScriptProgrammatic exportNo
Rails (rswag)RubyRake taskNo
Laravel (l5-swagger)PHPArtisan commandNo

Command

Choose the command matching your framework below. After extraction, always validate with speakeasy lint.

Python: FastAPI

FastAPI generates an OpenAPI schema at runtime. Export it without starting the server:

python -c "import json; from myapp import app; print(json.dumps(app.openapi()))" > openapi.json

Replace myapp with the module containing your FastAPI app instance. If the app uses a factory pattern:

python -c "import json; from myapp import create_app; app = create_app(); print(json.dumps(app.openapi()))" > openapi.json

You can also start the server and fetch from http://localhost:8000/openapi.json.

Python: Flask (flask-smorest)

Requires flask-smorest or apispec:

flask openapi write openapi.json

If using apispec directly, export programmatically:

import json
from myapp import create_app, spec
app = create_app()
with app.app_context():
    print(json.dumps(spec.to_dict()))

Python: Django REST Framework

Requires drf-spectacular:

python manage.py spectacular --file openapi.yaml

For JSON output:

python manage.py spectacular --format openapi-json --file openapi.json

Java: Spring Boot

Requires springdoc-openapi. Start the application, then fetch the spec:

# Start the app (background)
./mvnw spring-boot:run &
# Wait for startup
sleep 15

# Fetch the spec
curl http://localhost:8080/v3/api-docs -o openapi.json

# For YAML format
curl http://localhost:8080/v3/api-docs.yaml -o openapi.yaml

# Stop the app
kill %1

If the server runs on a different port or context path, adjust the URL accordingly.

TypeScript: NestJS

Requires @nestjs/swagger. Start the application, then fetch:

# Start the app (background)
npm run start &
sleep 10

# Fetch the spec (default path with SwaggerModule)
curl http://localhost:3000/api-json -o openapi.json

# Stop the app
kill %1

Alternatively, create a script to export without running the server:

// scripts/export-openapi.ts
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from '../src/app.module';
import * as fs from 'fs';

async function bootstrap() {
  const app = await NestFactory.create(AppModule, { logger: false });
  const config = new DocumentBuilder().setTitle('API').build();
  const doc = SwaggerModule.createDocument(app, config);
  fs.writeFileSync('openapi.json', JSON.stringify(doc, null, 2));
  await app.close();
}
bootstrap();

TypeScript: Hono (zod-openapi)

Requires @hono/zod-openapi. Export the schema programmatically:

// scripts/export-openapi.ts
import { app } from '../src/app';
import * as fs from 'fs';

const doc = app.doc('/doc', {
  openapi: '3.1.0',
  info: { title: 'API', version: '1.0.0' },
});
fs.writeFileSync('openapi.json', JSON.stringify(doc, null, 2));

Run with:

npx tsx scripts/export-openapi.ts

Ruby: Rails (rswag)

Requires rswag:

rails rswag:specs:swaggerize

The spec is written to swagger/v1/swagger.yaml by default (configurable in config/initializers/rswag_api.rb).

PHP: Laravel (l5-swagger)

Requires l5-swagger:

php artisan l5-swagger:generate

The spec is written to storage/api-docs/api-docs.json by default.

Post-Extraction Steps

After extracting the spec, always run these steps:

1. Validate the spec

speakeasy lint openapi --non-interactive -s openapi.json

2. Fix issues with overlays (if needed)

If validation reveals issues, use an overlay rather than modifying the extracted spec directly:

speakeasy overlay apply -s openapi.json -o fixes.yaml

To fix validation errors, create an OpenAPI overlay file and apply it with speakeasy overlay apply -s <spec> -o <overlay>.

3. Generate an SDK

speakeasy quickstart --skip-interactive --output console \
  -s openapi.json \
  -t <target> \
  -n <name> \
  -p <package>

Run speakeasy quickstart -s <spec> -t <language> to initialize a new SDK project.

Example

Full workflow for a FastAPI project:

# 1. Extract the OpenAPI spec
cd /path/to/my-fastapi-project
python -c "import json; from main import app; print(json.dumps(app.openapi()))" > openapi.json

# 2. Validate
speakeasy lint openapi --non-interactive -s openapi.json

# 3. Generate a TypeScript SDK
speakeasy quickstart --skip-interactive --output console \
  -s openapi.json \
  -t typescript \
  -n "MyApiSDK" \
  -p "my-api-sdk"

Adding Speakeasy Extensions

After extracting a spec, add Speakeasy-specific extensions for better SDK output. These can be added in framework config or via overlay.

FastAPI: Add Extensions via openapi_extra

@app.get(
    "/items",
    openapi_extra={
        "x-speakeasy-retries": {
            "strategy": "backoff",
            "backoff": {"initialInterval": 500, "maxInterval": 60000, "exponent": 1.5},
            "statusCodes": ["5XX", "429"]
        },
        "x-speakeasy-group": "items",
        "x-speakeasy-name-override": "list"
    }
)
def list_items(): ...

Django: Add Extensions via SPECTACULAR_SETTINGS

# settings.py
SPECTACULAR_SETTINGS = {
    # ... other settings
    'EXTENSIONS_TO_SCHEMA_FUNCTION': lambda generator, request, public: {
        'x-speakeasy-retries': {
            'strategy': 'backoff',
            'backoff': {'initialInterval': 500, 'maxInterval': 60000, 'exponent': 1.5},
            'statusCodes': ['5XX']
        }
    }
}

Spring Boot: Add Extensions via Custom OperationCustomizer

@Bean
public OperationCustomizer operationCustomizer() {
    return (operation, handlerMethod) -> {
        operation.addExtension("x-speakeasy-group",
            handlerMethod.getBeanType().getSimpleName().replace("Controller", "").toLowerCase());
        return operation;
    };
}

NestJS: Add Extensions via Decorator Options

@Get()
@ApiOperation({
  summary: 'List items',
  operationId: 'listItems'
})
@ApiExtension('x-speakeasy-group', 'items')
@ApiExtension('x-speakeasy-name-override', 'list')
listItems() { ... }

Via Overlay (Any Framework)

If you cannot modify framework code, use an overlay:

overlay: 1.0.0
info:
  title: Speakeasy Extensions
  version: 1.0.0
actions:
  - target: $.paths['/items'].get
    update:
      x-speakeasy-group: items
      x-speakeasy-name-override: list

Common Issues After Extraction

IssueSymptomFix
Missing operationIdsLint warning; SDK methods get generic namesAdd operationIds via overlay or use speakeasy suggest operation-ids -s openapi.json
Missing descriptionsLint hints; SDK has no documentationAdd descriptions to endpoints and schemas in source code or via overlay
Overly permissive schemasSchemas use additionalProperties: true or lack type constraintsTighten schemas in source code; use stricter validation decorators
No response schemasLint errors; SDK return types are any/objectAdd explicit response models to your framework endpoints
Duplicate operationIdsLint errors; generation failsEnsure each endpoint has a unique operationId
Missing authenticationNo security schemes in specAdd security metadata to your framework config or via overlay

What NOT to Do

  • Do NOT hand-write an OpenAPI spec when the framework can generate one -- always extract first
  • Do NOT edit the extracted spec directly -- use overlays for fixes so re-extraction does not lose changes
  • Do NOT skip validation -- extracted specs often have issues that block SDK generation
  • Do NOT assume the extracted spec is complete -- frameworks may omit auth, error responses, or headers
  • Do NOT start the server in production mode for extraction -- use development or test configuration

Troubleshooting

ErrorCauseSolution
ModuleNotFoundError (Python)App dependencies not installedRun pip install -r requirements.txt or pip install -e.
Connection refused (Spring Boot, NestJS)Server not fully startedIncrease sleep time or poll for readiness
Empty or minimal specRoutes not registered at import timeEnsure all route modules are imported; check lazy loading
YAML parse errorExtracted file has invalid syntaxRe-extract; check for print statements polluting stdout
Cannot find module (Node.js)Dependencies not installedRun npm install or yarn install
No /v3/api-docs endpoint (Spring Boot)springdoc not configuredAdd springdoc-openapi-starter-webmvc-ui to dependencies
No /api-json endpoint (NestJS)Swagger module not set upConfigure SwaggerModule.setup(app,...) in main.ts

Related Skills

  • manage-openapi-overlays - Add x-speakeasy-* extensions via overlay
  • start-new-sdk-project - Generate SDK after extraction

平台分布

Codex

35.12%
按下载量换算23

Claude

33.09%
按下载量换算22

Cursor

19.72%
按下载量换算13

Gemini CLI

9.86%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/speakeasy-api/agent-skills --skill extract-openapi-from-code 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills