diff --git a/.agents/skills/sync-backend-api/SKILL.md b/.agents/skills/sync-backend-api/SKILL.md index db43e288..f86187bb 100644 --- a/.agents/skills/sync-backend-api/SKILL.md +++ b/.agents/skills/sync-backend-api/SKILL.md @@ -144,10 +144,26 @@ export type XxxResponseData = z.output; src/data/dto//*.ts ``` +要求: + +- DTO class 的 `declare readonly` 只声明前端业务代码会直接访问的字段。 +- 不要因为后端响应包含某字段,就机械地为它增加 class 属性、嵌套类型或类型别名。 +- 后端返回但前端既不读取、也不透传的字段,可以不加入 schema 和 DTO。 +- 仅用于请求序列化、响应兼容或内部透传的字段保留在 schema 中,不添加 class 属性声明。 +- `Object.assign(this, data)` 会保留 schema 解析后的字段;即使 class 未声明对应属性,`toJson()` 仍可按 schema 正常序列化。 +- 新增 DTO 字段前先搜索实际调用点;没有直接读取方时默认不声明。 + DTO 统一模式: ```ts +export const XxxResponseSchema = z.object({ + id: z.string(), + // 仅用于内部透传,不需要在 DTO class 中声明。 + traceId: z.string(), +}); + export class XxxResponse { + // 业务代码直接读取的字段才公开声明。 declare readonly id: string; private constructor(input: XxxResponseInput) { @@ -365,4 +381,3 @@ pnpm exec vitest run 4. 更新状态机和 UI 调用。 5. 运行 `rg` 确认无残留引用。 6. 运行验证。 -