openapi-design
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenAPI Design Skill
OpenAPI设计技能
When to Use This Skill
何时使用此技能
Use this skill when:
- Designing REST APIs - OpenAPI 3.1 for contract-first API design
- Defining API contracts - Schemas, paths, parameters, responses
- API best practices - Naming conventions, status codes, versioning
使用此技能的场景:
- 设计REST API - 采用OpenAPI 3.1进行契约优先的API设计
- 定义API契约 - 包括模式、路径、参数、响应
- API最佳实践 - 命名规范、状态码、版本控制
MANDATORY: Documentation-First Approach
强制要求:文档优先方法
Before creating OpenAPI specifications:
- Invoke skill for API design patterns
docs-management - Verify OpenAPI 3.1 syntax via MCP servers (context7 for latest spec)
- Base all guidance on OpenAPI 3.1 specification
在创建OpenAPI规范之前:
- 调用技能获取API设计模式
docs-management - 通过MCP服务器验证OpenAPI 3.1语法(使用context7获取最新规范)
- 所有指导均基于OpenAPI 3.1规范
Contract-First Approach
契约优先方法
Why Contract-First?
为什么选择契约优先?
- Design before implementation: Think through API before coding
- Parallel development: Frontend and backend can work simultaneously
- Clear contract: Unambiguous specification for all parties
- Auto-generation: Generate clients, servers, documentation
- Validation: Validate requests/responses against schema
- 先设计再实现:在编码前先梳理清楚API的整体逻辑
- 并行开发:前端和后端团队可以同时开展工作
- 清晰的契约:为所有参与方提供明确无歧义的规范
- 自动生成:可自动生成客户端、服务端代码及文档
- 验证机制:依据模式验证请求/响应的合法性
Workflow
工作流程
text
Requirements → OpenAPI Spec → Review → Generate → Implement → Test
↑ ↓
←←←←←←←←←←←←← Iterate as needed ←←←←←←←←←←←←←←←←←←←←←←text
需求 → OpenAPI规范 → 评审 → 生成代码 → 开发实现 → 测试
↑ ↓
←←←←←←←←←←←←← 根据需要迭代优化 ←←←←←←←←←←←←←←←←←←←←←←OpenAPI 3.1 Structure Overview
OpenAPI 3.1结构概述
yaml
openapi: 3.1.0
info:
title: API Title
version: 1.0.0
description: API description
servers:
- url: https://api.example.com/v1
description: Production
tags:
- name: Orders
description: Order management
paths:
# Define endpoints - see paths-definition.md
components:
schemas: { }
securitySchemes: { }
responses: { }
parameters: { }For complete template: See paths-definition.md
yaml
openapi: 3.1.0
info:
title: API Title
version: 1.0.0
description: API description
servers:
- url: https://api.example.com/v1
description: Production
tags:
- name: Orders
description: Order management
paths:
# 定义端点 - 参考paths-definition.md
components:
schemas: { }
securitySchemes: { }
responses: { }
parameters: { }完整模板:请查看paths-definition.md
Quick Reference
快速参考
HTTP Methods
HTTP方法
| Method | Purpose | Idempotent |
|---|---|---|
| GET | Retrieve resource(s) | Yes |
| POST | Create resource | No |
| PUT | Replace resource | Yes |
| PATCH | Partial update | No |
| DELETE | Remove resource | Yes |
| 方法 | 用途 | 幂等性 |
|---|---|---|
| GET | 获取资源 | 是 |
| POST | 创建资源 | 否 |
| PUT | 替换资源 | 是 |
| PATCH | 部分更新资源 | 否 |
| DELETE | 删除资源 | 是 |
Common Status Codes
常见状态码
| Code | Use For |
|---|---|
| 200 | Successful GET, PUT, PATCH |
| 201 | Resource created (POST) |
| 204 | Successful DELETE |
| 400 | Malformed request |
| 401 | Authentication required |
| 404 | Resource not found |
| 422 | Validation error |
For complete guidance: See design-best-practices.md
| 状态码 | 使用场景 |
|---|---|
| 200 | 成功的GET、PUT、PATCH请求 |
| 201 | 资源创建成功(POST请求) |
| 204 | 成功的DELETE请求 |
| 400 | 请求格式错误 |
| 401 | 需要身份验证 |
| 404 | 资源不存在 |
| 422 | 验证失败 |
完整指导:请查看design-best-practices.md
Design Workflow
设计工作流
- Understand requirements: What operations are needed?
- Design resources: Identify entities and relationships
- Define schemas: Create reusable component schemas
- Specify endpoints: Define paths and operations
- Add security: Configure authentication/authorization
- Document examples: Add request/response examples
- Validate: Use linting tools (Spectral, etc.)
- Review: Get team feedback before implementation
- 理解需求:确定需要实现哪些操作?
- 设计资源:识别实体及它们之间的关系
- 定义模式:创建可复用的组件模式
- 指定端点:定义路径和操作
- 添加安全机制:配置身份验证/授权
- 添加示例文档:补充请求/响应示例
- 验证:使用 linting 工具(如Spectral等)
- 评审:在开发前获取团队反馈
References
参考资料
Load on-demand based on need:
| Reference | Load When |
|---|---|
| paths-definition.md | Defining REST endpoints, operations, parameters |
| components-definition.md | Creating schemas, responses, security schemes |
| design-best-practices.md | Reviewing naming, status codes, versioning |
根据需求按需加载:
| 参考资料 | 加载场景 |
|---|---|
| paths-definition.md | 定义REST端点、操作、参数时 |
| components-definition.md | 创建模式、响应、安全方案时 |
| design-best-practices.md | 评审命名、状态码、版本控制时 |
Related Skills (Cross-Plugin)
相关技能(跨插件)
| Phase | Skill | Plugin | Purpose |
|---|---|---|---|
| DESIGN | | formal-specification | Architecture research, pattern selection |
| AUTHORING | | spec-driven-development | Concrete YAML file creation |
| GOVERNANCE | | spec-driven-development | API governance, code generation |
Workflow: Design (research patterns) → Author (create YAML) → Govern (enforce contracts)
| 阶段 | 技能 | 插件 | 用途 |
|---|---|---|---|
| 设计 | | formal-specification | 架构调研、模式选择 |
| 编写 | | spec-driven-development | 创建具体的YAML文件 |
| 治理 | | spec-driven-development | API治理、代码生成 |
工作流: 设计(调研模式)→ 编写(创建YAML)→ 治理(执行契约)
External References
外部参考
- OpenAPI 3.1 Specification - Official specification
- RFC 7231 - HTTP Semantics - HTTP methods and status codes
- RFC 7807 - Problem Details - Standard error response format
- Spectral - OpenAPI linting tool
- OpenAPI 3.1 Specification - 官方规范
- RFC 7231 - HTTP Semantics - HTTP方法和状态码
- RFC 7807 - Problem Details - 标准错误响应格式
- Spectral - OpenAPI linting工具
MCP Research
MCP调研
For current OpenAPI patterns and tools:
text
perplexity: "OpenAPI 3.1 specification" "REST API design patterns"
context7: "openapi" (for official documentation)
ref: "OpenAPI spec examples" "JSON Schema patterns"如需了解当前OpenAPI模式和工具:
text
perplexity: "OpenAPI 3.1 specification" "REST API design patterns"
context7: "openapi"(用于获取官方文档)
ref: "OpenAPI spec examples" "JSON Schema patterns"Version History
版本历史
- v2.0.0 (2026-01-17): Refactored to progressive disclosure pattern
- Extracted 3 reference files (~500 lines)
- Hub reduced from 698 to ~130 lines
- v1.0.0 (2025-12-26): Initial release
Last Updated: 2026-01-17
- v2.0.0(2026-01-17):重构为渐进式披露模式
- 提取3个参考文件(约500行)
- 核心内容从698行精简至约130行
- v1.0.0(2025-12-26):初始发布
最后更新时间: 2026-01-17