work-order-monitor/data/api/README.md

33 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# API 开发与类型定义流程
当前接口与类型定义以 OpenAPI 文档为准:
- 源文件:`data/api/默认模块.openapi.json`
- 来源:该文件由 **Apifox 导出**
- 内容:包含接口定义、字段说明、请求/响应示例
## 1. 更新 OpenAPI 文档
- 在 Apifox 中维护接口后,导出最新 OpenAPI 文件并覆盖 `data/api/默认模块.openapi.json`
- 新增/修改接口时先以该文件为唯一事实来源Single Source of Truth
## 2. 生成/更新接口层 (src/api/)
- 根据 `paths` 中的接口定义,更新 `src/api/` 下的请求函数(路径、方法、请求参数)。
- 保持现有业务兼容时,可新增标准方法并保留旧方法别名。
## 3. 生成/更新类型定义 (src/api/types/)
- 根据 OpenAPI 中的 schema、字段说明和示例维护 `src/api/types/` 下类型。
-`src/api/types/index.ts` 统一导出类型。
- 新增字段时补充必要注释,命名与接口字段保持一致。
## 4. 使用与校验
- 在业务层使用 `ApiResponse<T>` 包装响应类型。
- 修改后执行类型检查:
```bash
npm run type-check
```