Files
mock-server/.claude/rules/mock-spec.md
CNWei ddfa4f3b5a docs: 重构项目文档结构
- 将 CLAUDE.md 移至 .claude/ 目录,精简为 AI 开发指南
- 扩充 README.md 为完整的用户文档
- 新增 rules/mock-spec.md: YAML 配置生成规范
- 新增 rules/commit-spec.md: Git 提交消息格式规范
- 从 .gitignore 移除 .claude/ 目录以便跟踪

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-24 18:44:06 +08:00

2.1 KiB

paths
paths
mocks/**/*.{yml,yaml}

YAML 配置规范

AI 在生成 Mock 规则时必须遵循以下格式。

字段说明

字段 类型 必填 说明
id string 规则唯一标识
request.method string HTTP 方法 (GET/POST/PUT/DELETE...)
request.path string 请求路径,精确匹配
request.query_params object 查询参数匹配
request.headers object 请求头匹配(大小写不敏感)
request.body any 请求体匹配,支持 JSON 对象或字符串
response.status number HTTP 状态码
response.headers object 响应头
response.body string 响应体,支持 file:// 前缀
settings.delay_ms number 延迟响应(毫秒)

匹配规则

  1. 路径精确匹配(非前缀匹配)
  2. 请求头匹配大小写不敏感
  3. Body 匹配支持 JSON 对象或字符串比较

配置示例

单接口模式:

id: "login"
request:
  method: "POST"
  path: "/api/login"
  body: { "username": "test" }
response:
  status: 200
  body: '{"token": "xxx"}'
settings:
  delay_ms: 100

多接口模式(数组):

- id: "get-users"
  request: { method: "GET", path: "/api/users" }
  response: { status: 200, body: '{"users": []}' }

- id: "create-user"
  request: { method: "POST", path: "/api/users" }
  response: { status: 201, body: '{"id": 1}' }

带查询参数和请求头:

id: "search-users"
request:
  method: "GET"
  path: "/api/users"
  query_params: { "role": "admin" }
  headers: { "Authorization": "Bearer token" }
response:
  status: 200
  headers: { "X-Total-Count": "100" }
  body: '{"users": []}'

文件响应:

id: "download-pdf"
request:
  method: "GET"
  path: "/api/download"
response:
  status: 200
  body: "file://./data/large-file.pdf"

file:// 支持两种路径:

  • 相对路径:file://./data/file.pdf(相对于项目根目录)
  • 绝对路径:file:///C:/path/to/file.pdf