← 返回 Skills 市场
kmpanda011172

OpenAPI Contract-Driven Development

作者 kmpanda011172 · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
40
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install openapi-contract-driven
功能描述
OpenAPI 契约驱动开发工作流。解决多 Agent 协作中「前端自造端点,后端漏实现」 这个系统性缺陷。Use when: (1) 新项目启动或已有项目需要规范 API 协作, (2) 频繁出现"页面空白 / 500 / 502"但找不到根因, (3) 需要在多人/AI agent 团队中建立 API 契约体...
使用说明 (SKILL.md)

OpenAPI Contract-Driven Development

一句话:让前端 agent 连犯错的机会都没有。

解决的问题

pm-agent 漏需求 → 架构漏设计 → 前端自造端点 → 后端没实现 → 用户看到 500

          ↓ 本 Skill 在此切断
          
OpenAPI YAML 是唯一契约 → 代码生成 → 前端只能调生成的函数 → 编译期暴露缺口

核心原理

防线 机制 拦截什么
① 契约层 check-api-rules.sh 7条规则 operationId缺失、ApiResponse未包裹、ErrorResponse缺失
② 代码生成 apiClient.ts 从前端唯一入口 手写 fetch/axios、自造端点
③ 运行时 ops-agent 逐端口 curl 路由错误、服务宕机、端口不匹配
④ 设计审计 coordinator 前后端期望对照 架构漏设计、需求未覆盖

快速开始

1. 安装

# 安装本 skill(在 skills/ 目录下)
cp -r openapi-contract-driven ~/.openclaw/workspace/skills/

# 安装 openapi-typescript(前端代码生成用,可选)
npm install -D openapi-typescript

2. 从模板生成项目 OpenAPI 规范

cp references/openapi-template.yaml standards/{project}-openapi.yaml
# 编辑 YAML,定义你的端点

3. 生成前端 API Client

# 手动编写 apiClient.ts(或基于 YAML 自动生成)
# 模板见 references/apiClient-template.ts

# 或使用 openapi-typescript 生成类型文件
npx openapi-typescript standards/{project}-openapi.yaml -o frontend/src/api/generated/schema.d.ts

4. 配置 Agent 团队

references/agent-templates/ 下的 AGENTS.md 片段合并到对应角色的 Agent 配置中:

模板文件 合并到
architecture-agent.md arch-agent / saas-arch-agent 的 AGENTS.md
backend-agent.md backend-agent / legal-backend-agent 的 AGENTS.md
frontend-agent.md frontend-agent / legal-frontend-agent 的 AGENTS.md
ops-agent.md ops-agent / saas-ops-agent 的 AGENTS.md
coordinator.md 小雨(main agent)的 coordinator-spawn-template.md

5. 验证

# 规范检查
bash scripts/check-api-rules.sh standards/{project}-openapi.yaml

# 期望输出:✅ 6/7 通过 (日期 format 为建议项,不阻塞)

工作流

                    ┌─────────────────────────────┐
                    │  pm-agent: 产品需求           │
                    └──────────────┬──────────────┘
                                   ▼
                    ┌─────────────────────────────┐
                    │  arch-agent: 架构设计         │
                    │  → 输出 OpenAPI YAML (强制)   │
                    └──────────────┬──────────────┘
                                   ▼
                    ┌─────────────────────────────┐
                    │  coordinator: 对照审计         │
                    │  前端期望 vs YAML 定义         │
                    └──────────────┬──────────────┘
                           ┌───────┴───────┐
                           ▼               ▼
              ┌──────────────────┐ ┌──────────────────┐
              │ frontend-agent    │ │ backend-agent     │
              │ 只 import 生成的   │ │ 对照 YAML 实现    │
              │ apiClient         │ │ Controller        │
              └────────┬─────────┘ └────────┬─────────┘
                       │                    │
                       └────────┬───────────┘
                                ▼
                    ┌─────────────────────────────┐
                    │  ops-agent: 部署后验证        │
                    │  ① check-api-rules.sh        │
                    │  ② curl 逐端口逐端点          │
                    └─────────────────────────────┘

7 条核心规则

.spectral.yaml 规则集(不与 Spectral CLI 耦合,bash 脚本可独立运行):

  1. operationId 完整性 — 前端代码生成强依赖(error)
  2. ApiResponse 强制 wrapper — 防止「有的返回 T,有的返回 {data:T}」(error)
  3. ErrorResponse 标准模型 — 前端不用猜 error shape(warn)
  4. 分页参数统一 — PageParam + SizeParam + SortParam(warn)
  5. health 端点 — 每个服务必须暴露(warn)
  6. 日期格式显式标注format: date-time(warn)
  7. BearerAuth securityScheme — 统一认证声明(error)

跨项目验证

已在两个项目上跑通:

项目 端点 规则检查 apiClient
LexGuard(法律合同审查) 30 6/7 ✅ 11KB
寓居智联(资产管理) 46 6/7 ✅ 17KB

参考资料

安全使用建议
Install this if you want agents to follow a stricter OpenAPI contract workflow. Review the AGENTS.md snippets before merging them, because they deliberately constrain how frontend, backend, architecture, ops, and coordinator agents create or validate API work.
能力评估
Purpose & Capability
The files consistently support OpenAPI contract-driven development: YAML templates, role-specific agent guidance, a TypeScript API client template, and a shell checker for API rules.
Instruction Scope
The skill asks users to merge role templates into agent configuration, which intentionally changes agent behavior, but the scope is explicit and limited to API contract design, implementation, frontend calls, and deployment checks.
Install Mechanism
Installation is documented as copying the skill into the OpenClaw skills directory, with an optional npm dev dependency for openapi-typescript; no covert installer, postinstall hook, or automatic execution was found.
Credentials
The shell script reads a user-supplied OpenAPI YAML with grep and prints validation results; the ops guidance uses local curl checks against configured service ports, which fits the stated deployment verification purpose.
Persistence & Privilege
Persistent changes are limited to the installed skill files and any user-directed merging of AGENTS.md snippets; there is no background worker, credential harvesting, destructive action, or privilege escalation.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install openapi-contract-driven
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /openapi-contract-driven 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
OpenAPI 契约驱动开发的首次发布,建立多 Agent 团队的 API 协作规范。 - 通过 OpenAPI 为唯一契约源,强制切断前端自造端点、后端漏实现的风险 - 提供 7 条核心 API 规则与 check-api-rules.sh 校验脚本 - 支持前端通过自动生成的 apiClient 接入接口,编译期暴露缺口 - 给出多 Agent 团队的配置和协作说明,适配前后端、架构与运维角色 - 适用场景与非适用场景描述清晰,已在多个项目实践验证
元数据
Slug openapi-contract-driven
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

OpenAPI Contract-Driven Development 是什么?

OpenAPI 契约驱动开发工作流。解决多 Agent 协作中「前端自造端点,后端漏实现」 这个系统性缺陷。Use when: (1) 新项目启动或已有项目需要规范 API 协作, (2) 频繁出现"页面空白 / 500 / 502"但找不到根因, (3) 需要在多人/AI agent 团队中建立 API 契约体... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 40 次。

如何安装 OpenAPI Contract-Driven Development?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install openapi-contract-driven」即可一键安装,无需额外配置。

OpenAPI Contract-Driven Development 是免费的吗?

是的,OpenAPI Contract-Driven Development 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

OpenAPI Contract-Driven Development 支持哪些平台?

OpenAPI Contract-Driven Development 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 OpenAPI Contract-Driven Development?

由 kmpanda011172(@kmpanda011172)开发并维护,当前版本 v1.0.0。

💬 留言讨论