openapi-spec-generation
它能做什么
这个工具可以帮你创建和整理 API 文档(API 是让程序之间相互通信的接口)。它既可以根据你的代码生成文档,也可以根据之前的设计稿生成。
适用场景
- ✓需要为一个新的 API 编写文档时。
- ✓想为代码中已有的 API 生成文档时。
- ✓需要为其他程序编写使用 API 的指南时。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/documentation-generation/skills/openapi-spec-generation/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“为这个接收用户数据的 API 创建 OpenAPI 文档。”
每周 5 个新技能,1 分钟读完。
工作原理
工具会分析你的代码或设计文件,理解 API 的工作方式,然后生成一个标准化的文件(OpenAPI 3.1),详细描述 API 的所有细节。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
OpenAPI Spec Generation
Comprehensive patterns for creating, maintaining, and validating OpenAPI 3.1 specifications for RESTful APIs.
When to Use This Skill
- Creating API documentation from scratch
- Generating OpenAPI specs from existing code
- Designing API contracts (design-first approach)
- Validating API implementations against specs
- Generating client SDKs from specs
- Setting up API documentation portals
Core Concepts
1. OpenAPI 3.1 Structure
openapi: 3.1.0
info:
title: API Title
version: 1.0.0
servers:
- url: https://api.example.com/v1
paths:
/resources:
get: ...
components:
schemas: ...
securitySchemes: ...
2. Design Approaches
| Approach | Description | Best For |
|---|---|---|
| Design-First | Write spec before code | New APIs, contracts |
| Code-First | Generate spec from code | Existing APIs |
| Hybrid | Annotate code, generate spec | Evolving APIs |
Templates and detailed worked examples
Full template library and detailed worked examples live in references/details.md. Read that file when you need the concrete templates.
Best Practices
Do's
- Use $ref - Reuse schemas, parameters, responses
- Add examples - Real-world values help consumers
- Document errors - All possible error codes
- Version your API - In URL or header
- Use semantic versioning - For spec changes
Don'ts
- Don't use generic descriptions - Be specific
- Don't skip security - Define all schemes
- Don't forget nullable - Be explicit about null
- Don't mix styles - Consistent naming throughout
- Don't hardcode URLs - Use server variables
常见问题
什么是 OpenAPI?
它是一种描述 API 的标准格式,就像一张地图,告诉别人如何使用某项在线服务。
“Design-First”和“Code-First”有什么区别?
“Design-First”是先绘制地图(编写文档),再修建道路(开发 API);“Code-First”则是先修建道路,再根据道路生成地图。
为什么要用“$ref”?
它就像一个快捷方式,可以避免重复描述相同的信息。如果你在某处描述了一种数据类型,就可以用“$ref”在其他地方直接引用它。
详情
作者的原始描述
Generate and maintain OpenAPI 3.1 specifications from code, design-first specs, and validation patterns. Use when creating API documentation, generating SDKs, or ensuring API contract compliance.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6690
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …