feat: add typed error message templates and stable replay snapshots
This commit is contained in:
15
API.md
15
API.md
@@ -130,6 +130,21 @@ errorCatalog CommonErrors (
|
||||
|
||||
同一 HTTP 200 下,OpenAPI 用 `anyOf` 保留成功 DTO 和错误体,日志与指标仍识别业务失败。完整语法、路由作用域与手写项目配置见 [统一错误目录](errors/README.md),可运行契约见 [errors.api](examples/contracts/errors.api)。
|
||||
|
||||
从 `v0.11.0-preview` 起,目录条目支持 `params` 有序列表与 `{name}` 提示模板:
|
||||
|
||||
```json
|
||||
"TextTooLong": {
|
||||
"key": "TEXT_TOO_LONG", "code": 400002,
|
||||
"message": "{label}不能超过{max}个字符",
|
||||
"params": [
|
||||
{"name": "label", "type": "string", "example": "企业名称"},
|
||||
{"name": "max", "type": "int", "example": 100}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
生成 `apierrors.TextTooLong(label string, max int)`,返回时 Message 已填好;固定提示保持无参数函数。声明顺序决定参数顺序。模板校验、运行时缺参/类型错误、转义及非 HTTP 使用规则见 [提示模板参数](errors/README.md)。OpenAPI 的错误目录保留参数定义,响应示例使用具体文案。
|
||||
|
||||
原有声明继续支持:
|
||||
|
||||
```go
|
||||
|
||||
Reference in New Issue
Block a user