AgentSkillsCN

api-contract

在变更前后验证API契约。记录当前契约(参数、响应、状态码),对比拟议的变更差异,标记可能引发断裂的变更及其受影响的客户端。在更改API路由文件、Zod模式或响应类型时,或当用户提及API/端点/路由时使用此功能。

SKILL.md
--- frontmatter
name: api-contract
description: Validates API contracts before and after changes. Documents current contract (params, response, status codes), diffs proposed changes, flags breaking changes and affected clients. Use when changing API route files, Zod schemas, or response types, or when user mentions API/endpoint/route.

API Contract Validator

When to Trigger

  • Changes to API route files (src/app/api/**/route.ts)
  • Changes to Zod schemas
  • Changes to response types
  • User mentions "API", "endpoint", "route"

What to Do

Step 1: Extract Current Contract

Document:

  • Endpoint and method
  • Auth requirement
  • Request params (types, optional/required)
  • Response shape (data, meta, etc.)
  • Status codes (200, 401, 500, etc.)

Step 2: Compare with Proposed Changes

Show diff of params and response. Mark: unchanged ✅, new ⚠️, removed ❌.

Step 3: Report

Output:

markdown
## API Contract Changes

### Endpoint: [METHOD] [path]

#### Request Parameters
[BEFORE/AFTER or unchanged/new/removed]

#### Response Body
BEFORE: [shape]
AFTER: [shape]
Breaking: Yes/No | Backwards compatible: Yes/No

#### Affected Clients:
- [Client name]: Compatible / Update needed

#### Migration for Clients:
[Code examples for old vs new usage]

If breaking (e.g. changing { data: [] } to raw array), recommend: new v2 endpoint, or optional query param (e.g. ?format=array) while keeping default. Do not proceed with breaking change without explicit migration strategy.