@done-coding/schema-api 0.0.1-alpha.1 → 0.0.1-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,8 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "common-error-codes.schema.json",
4
4
  "title": "CommonErrorCodes",
5
- "description": "通用失败码表:每个码固定 HTTP 状态(x-httpStatus),并给出能否重试与是否已执行的缺省值(default)。错误体引用本表:code 是通用失败码时,服务未另行指定 error.retryable 与 error.outcome 就取表中值;服务能确定更具体的重试性或执行结局时可以覆盖,任何合法的 retryable 与 outcome 都合法。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
5
+ "description": "通用失败码表(参考资源):每个码给出 HTTP 状态(x-httpStatus),以及能否重试与是否已执行的参考值(x-referenceValue)。本表不约束任何结构:错误体不引用它,包不替使用方填写;使用方可显式引用表中值。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
6
+ "x-referenceResource": true,
6
7
  "$defs": {
7
8
  "code": {
8
9
  "description": "通用失败码。",
@@ -33,8 +34,8 @@
33
34
  "properties": {
34
35
  "error": {
35
36
  "properties": {
36
- "retryable": { "default": false },
37
- "outcome": { "default": "not_executed" }
37
+ "retryable": { "x-referenceValue": false },
38
+ "outcome": { "x-referenceValue": "not_executed" }
38
39
  }
39
40
  }
40
41
  }
@@ -51,8 +52,8 @@
51
52
  "properties": {
52
53
  "error": {
53
54
  "properties": {
54
- "retryable": { "default": false },
55
- "outcome": { "default": "not_executed" }
55
+ "retryable": { "x-referenceValue": false },
56
+ "outcome": { "x-referenceValue": "not_executed" }
56
57
  }
57
58
  }
58
59
  }
@@ -69,8 +70,8 @@
69
70
  "properties": {
70
71
  "error": {
71
72
  "properties": {
72
- "retryable": { "default": false },
73
- "outcome": { "default": "not_executed" }
73
+ "retryable": { "x-referenceValue": false },
74
+ "outcome": { "x-referenceValue": "not_executed" }
74
75
  }
75
76
  }
76
77
  }
@@ -87,8 +88,8 @@
87
88
  "properties": {
88
89
  "error": {
89
90
  "properties": {
90
- "retryable": { "default": false },
91
- "outcome": { "default": "not_executed" }
91
+ "retryable": { "x-referenceValue": false },
92
+ "outcome": { "x-referenceValue": "not_executed" }
92
93
  }
93
94
  }
94
95
  }
@@ -105,8 +106,8 @@
105
106
  "properties": {
106
107
  "error": {
107
108
  "properties": {
108
- "retryable": { "default": false },
109
- "outcome": { "default": "not_executed" }
109
+ "retryable": { "x-referenceValue": false },
110
+ "outcome": { "x-referenceValue": "not_executed" }
110
111
  }
111
112
  }
112
113
  }
@@ -123,8 +124,8 @@
123
124
  "properties": {
124
125
  "error": {
125
126
  "properties": {
126
- "retryable": { "default": false },
127
- "outcome": { "default": "not_executed" }
127
+ "retryable": { "x-referenceValue": false },
128
+ "outcome": { "x-referenceValue": "not_executed" }
128
129
  }
129
130
  }
130
131
  }
@@ -141,8 +142,8 @@
141
142
  "properties": {
142
143
  "error": {
143
144
  "properties": {
144
- "retryable": { "default": false },
145
- "outcome": { "default": "not_executed" }
145
+ "retryable": { "x-referenceValue": false },
146
+ "outcome": { "x-referenceValue": "not_executed" }
146
147
  }
147
148
  }
148
149
  }
@@ -159,8 +160,8 @@
159
160
  "properties": {
160
161
  "error": {
161
162
  "properties": {
162
- "retryable": { "default": true },
163
- "outcome": { "default": "not_executed" }
163
+ "retryable": { "x-referenceValue": true },
164
+ "outcome": { "x-referenceValue": "not_executed" }
164
165
  }
165
166
  }
166
167
  }
@@ -177,8 +178,8 @@
177
178
  "properties": {
178
179
  "error": {
179
180
  "properties": {
180
- "retryable": { "default": false },
181
- "outcome": { "default": "unknown" }
181
+ "retryable": { "x-referenceValue": false },
182
+ "outcome": { "x-referenceValue": "unknown" }
182
183
  }
183
184
  }
184
185
  }
@@ -195,8 +196,8 @@
195
196
  "properties": {
196
197
  "error": {
197
198
  "properties": {
198
- "retryable": { "default": false },
199
- "outcome": { "default": "unknown" }
199
+ "retryable": { "x-referenceValue": false },
200
+ "outcome": { "x-referenceValue": "unknown" }
200
201
  }
201
202
  }
202
203
  }
@@ -213,8 +214,8 @@
213
214
  "properties": {
214
215
  "error": {
215
216
  "properties": {
216
- "retryable": { "default": true },
217
- "outcome": { "default": "unknown" }
217
+ "retryable": { "x-referenceValue": true },
218
+ "outcome": { "x-referenceValue": "unknown" }
218
219
  }
219
220
  }
220
221
  }
@@ -14,10 +14,9 @@
14
14
  "maxLength": 1024
15
15
  },
16
16
  "limit": {
17
- "description": "本批最多取多少条;缺省值由各接口自定。",
17
+ "description": "本批最多取多少条,至少 1;不带时取多少条、上限多少由接口自己声明。",
18
18
  "type": "integer",
19
- "minimum": 1,
20
- "maximum": 100
19
+ "minimum": 1
21
20
  }
22
21
  },
23
22
  "additionalProperties": false
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "error-body.schema.json",
4
4
  "title": "ErrorBody",
5
- "description": "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。",
5
+ "description": "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。retryable 与 outcome 由服务按实际情形填写,包不替使用方填写;通用失败码表给了一组参考值,使用方可显式引用。",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "code": {
@@ -34,7 +34,6 @@
34
34
  },
35
35
  "required": ["code", "message", "data", "error", "requestId"],
36
36
  "additionalProperties": false,
37
- "allOf": [{ "$ref": "common-error-codes.schema.json" }],
38
37
  "$defs": {
39
38
  "errorDetail": {
40
39
  "title": "ErrorDetail",
@@ -0,0 +1,23 @@
1
+ {
2
+ "$schema": "https://json-schema.org/draft/2020-12/schema",
3
+ "$id": "list-reference-values.schema.json",
4
+ "title": "ListReferenceValues",
5
+ "description": "列表的参考数值(参考资源):只是参考,不约束任何结构。结构定义里页码、每页条数、每批条数都没有默认值和上限,包不替使用方填写;要用这些数值须在自己的代码里显式引用,或声明自己的值。",
6
+ "x-referenceResource": true,
7
+ "x-referenceValues": {
8
+ "PAGED_LIST_REFERENCE_VALUES": {
9
+ "description": "页码式列表的参考数值:page 是请求不带页码时可参考的页码,pageSize 是请求不带每页条数时可参考的条数,maxPageSize 是每页条数可参考的上限。",
10
+ "value": {
11
+ "page": 1,
12
+ "pageSize": 10,
13
+ "maxPageSize": 100
14
+ }
15
+ },
16
+ "CURSOR_LIST_REFERENCE_VALUES": {
17
+ "description": "游标式列表的参考数值:maxLimit 是每批条数可参考的上限。",
18
+ "value": {
19
+ "maxLimit": 100
20
+ }
21
+ }
22
+ }
23
+ }
@@ -8,17 +8,14 @@
8
8
  "type": "object",
9
9
  "properties": {
10
10
  "page": {
11
- "description": "页码,从 1 开始。",
11
+ "description": "页码,从 1 开始;不带时的含义由接口自己声明。",
12
12
  "type": "integer",
13
- "minimum": 1,
14
- "default": 1
13
+ "minimum": 1
15
14
  },
16
15
  "pageSize": {
17
- "description": "每页条数。",
16
+ "description": "每页条数,至少 1;不带时的含义与上限由接口自己声明。",
18
17
  "type": "integer",
19
- "minimum": 1,
20
- "maximum": 100,
21
- "default": 10
18
+ "minimum": 1
22
19
  },
23
20
  "query": {
24
21
  "description": "模糊搜索词,最多 200 个字符。",
@@ -27,10 +27,9 @@
27
27
  "minimum": 0
28
28
  },
29
29
  "pageSize": {
30
- "description": "每页条数,回显请求值。",
30
+ "description": "每页条数,回显请求值,至少 1。",
31
31
  "type": "integer",
32
- "minimum": 1,
33
- "maximum": 100
32
+ "minimum": 1
34
33
  },
35
34
  "totalPage": {
36
35
  "description": "总页数。",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "service-error-codes.schema.json",
4
4
  "title": "ServiceErrorCodes",
5
- "description": "一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。",
5
+ "description": "一个服务的专有业务码清单。OK 与 HTTP_<数字> 形式的码是结构保留字,不得使用;比较按字节精确进行,不做大小写归一。专有码是否要避开某组通用码由使用方显式检查:把那组码传给参考资源出口的检查函数,不传就不比。",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "service": {
@@ -33,8 +33,7 @@
33
33
  "pattern": "^(?:[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$",
34
34
  "allOf": [
35
35
  { "not": { "const": "OK" } },
36
- { "not": { "type": "string", "pattern": "^HTTP_[0-9]+$" } },
37
- { "not": { "$ref": "common-error-codes.schema.json#/$defs/code" } }
36
+ { "not": { "type": "string", "pattern": "^HTTP_[0-9]+$" } }
38
37
  ]
39
38
  },
40
39
  "stage": {
package/types/index.d.ts CHANGED
@@ -1,10 +1,3 @@
1
- /**
2
- * BoundedList 响应里各字段的路径(由定义 bounded-list.schema.json 生成)。
3
- */
4
- export declare const BOUNDED_LIST_RESPONSE_PATHS: {
5
- readonly items: "items";
6
- };
7
-
8
1
  /** 一次性列表,TItem 是元素类型。 */
9
2
  export declare interface BoundedList<TItem = unknown> extends Omit<Generated.BoundedList, "items"> {
10
3
  items: TItem[];
@@ -25,119 +18,6 @@ declare interface BoundedList_2 {
25
18
  /** BoundedList:bounded-list.schema.json */
26
19
  export declare const boundedListSchema: SchemaDocument;
27
20
 
28
- /**
29
- * 通用失败码 → HTTP 状态、能否重试与是否已执行(outcome)的缺省值、含义。
30
- * retryable 与 outcome 是缺省值:服务未另行指定时取表中值,能确定更具体的情形时可以覆盖。
31
- */
32
- export declare const COMMON_ERROR_CODE_TABLE: {
33
- readonly INVALID_REQUEST: {
34
- readonly httpStatus: 400;
35
- readonly retryable: false;
36
- readonly outcome: "not_executed";
37
- readonly meaning: "请求不符合接口契约";
38
- };
39
- readonly UNAUTHENTICATED: {
40
- readonly httpStatus: 401;
41
- readonly retryable: false;
42
- readonly outcome: "not_executed";
43
- readonly meaning: "未登录,或令牌无效、过期";
44
- };
45
- readonly FORBIDDEN: {
46
- readonly httpStatus: 403;
47
- readonly retryable: false;
48
- readonly outcome: "not_executed";
49
- readonly meaning: "已认证但无权执行";
50
- };
51
- readonly NOT_FOUND: {
52
- readonly httpStatus: 404;
53
- readonly retryable: false;
54
- readonly outcome: "not_executed";
55
- readonly meaning: "资源不存在,或调用方无权得知其存在";
56
- };
57
- readonly ROUTE_NOT_FOUND: {
58
- readonly httpStatus: 404;
59
- readonly retryable: false;
60
- readonly outcome: "not_executed";
61
- readonly meaning: "接口路径不存在";
62
- };
63
- readonly METHOD_NOT_ALLOWED: {
64
- readonly httpStatus: 405;
65
- readonly retryable: false;
66
- readonly outcome: "not_executed";
67
- readonly meaning: "接口不支持该 HTTP 方法";
68
- };
69
- readonly CONFLICT: {
70
- readonly httpStatus: 409;
71
- readonly retryable: false;
72
- readonly outcome: "not_executed";
73
- readonly meaning: "资源状态冲突";
74
- };
75
- readonly RATE_LIMITED: {
76
- readonly httpStatus: 429;
77
- readonly retryable: true;
78
- readonly outcome: "not_executed";
79
- readonly meaning: "请求过于频繁,可稍后重试";
80
- };
81
- readonly INTERNAL_ERROR: {
82
- readonly httpStatus: 500;
83
- readonly retryable: false;
84
- readonly outcome: "unknown";
85
- readonly meaning: "服务内部错误,可能已产生副作用";
86
- };
87
- readonly LIST_LIMIT_EXCEEDED: {
88
- readonly httpStatus: 500;
89
- readonly retryable: false;
90
- readonly outcome: "unknown";
91
- readonly meaning: "一次性列表的结果超出接口声明的上限";
92
- };
93
- readonly SERVICE_UNAVAILABLE: {
94
- readonly httpStatus: 503;
95
- readonly retryable: true;
96
- readonly outcome: "unknown";
97
- readonly meaning: "服务或其依赖暂不可用";
98
- };
99
- };
100
-
101
- /**
102
- * 通用失败码。错误体的 code 是开放字符串,这里只列通用的一组;
103
- * 各服务可以有自己的专有码,遇到不认识的码按 HTTP 状态归类处理。
104
- */
105
- export declare const COMMON_ERROR_CODES: {
106
- readonly INVALID_REQUEST: "INVALID_REQUEST";
107
- readonly UNAUTHENTICATED: "UNAUTHENTICATED";
108
- readonly FORBIDDEN: "FORBIDDEN";
109
- readonly NOT_FOUND: "NOT_FOUND";
110
- readonly ROUTE_NOT_FOUND: "ROUTE_NOT_FOUND";
111
- readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
112
- readonly CONFLICT: "CONFLICT";
113
- readonly RATE_LIMITED: "RATE_LIMITED";
114
- readonly INTERNAL_ERROR: "INTERNAL_ERROR";
115
- readonly LIST_LIMIT_EXCEEDED: "LIST_LIMIT_EXCEEDED";
116
- readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
117
- };
118
-
119
- export declare type CommonErrorCode = (typeof COMMON_ERROR_CODES)[keyof typeof COMMON_ERROR_CODES];
120
-
121
- /** CommonErrorCodes:common-error-codes.schema.json */
122
- export declare const commonErrorCodesSchema: SchemaDocument;
123
-
124
- /**
125
- * CursorListRequest 的线上参数名(由定义 cursor-list-request.schema.json 生成)。
126
- */
127
- export declare const CURSOR_LIST_REQUEST_PARAMS: {
128
- readonly after: "cursor.after";
129
- readonly limit: "cursor.limit";
130
- };
131
-
132
- /**
133
- * CursorList 响应里各字段的路径(由定义 cursor-list.schema.json 生成)。
134
- */
135
- export declare const CURSOR_LIST_RESPONSE_PATHS: {
136
- readonly items: "items";
137
- readonly next: "cursor.next";
138
- readonly hasMore: "cursor.hasMore";
139
- };
140
-
141
21
  /** 游标式列表,TItem 是元素类型。 */
142
22
  export declare interface CursorList<TItem = unknown> extends Omit<Generated.CursorList, "items"> {
143
23
  items: TItem[];
@@ -178,7 +58,7 @@ export declare interface CursorListRequest {
178
58
  */
179
59
  after?: string;
180
60
  /**
181
- * 本批最多取多少条;缺省值由各接口自定。
61
+ * 本批最多取多少条,至少 1;不带时取多少条、上限多少由接口自己声明。
182
62
  */
183
63
  limit?: number;
184
64
  }
@@ -190,7 +70,7 @@ export declare const cursorListRequestSchema: SchemaDocument;
190
70
  export declare const cursorListSchema: SchemaDocument;
191
71
 
192
72
  /**
193
- * 错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。
73
+ * 错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。retryable 与 outcome 由服务按实际情形填写,包不替使用方填写;通用失败码表给了一组参考值,使用方可显式引用。
194
74
  */
195
75
  export declare interface ErrorBody {
196
76
  /**
@@ -283,16 +163,6 @@ declare namespace Generated {
283
163
  }
284
164
  }
285
165
 
286
- /**
287
- * ListFilter 的线上参数名(由定义 list-filter.schema.json 生成)。
288
- */
289
- export declare const LIST_FILTER_PARAMS: {
290
- readonly prefix: "filter.";
291
- readonly operators: {
292
- readonly eq: "eq";
293
- };
294
- };
295
-
296
166
  /**
297
167
  * 列表的筛选参数。线上写作 filter.<字段>.<操作>(如 filter.status.eq=active),本定义约束解码后的对象 {<字段>: {<操作>: 值}};字段为小驼峰,可筛选哪些字段由接口自己声明。首版操作只有 eq。前缀下未声明的参数不合法。
298
168
  */
@@ -316,26 +186,6 @@ export declare interface ListFilterCondition {
316
186
  /** ListFilter:list-filter.schema.json */
317
187
  export declare const listFilterSchema: SchemaDocument;
318
188
 
319
- /**
320
- * PagedListRequest 的线上参数名(由定义 paged-list-request.schema.json 生成)。
321
- */
322
- export declare const PAGED_LIST_REQUEST_PARAMS: {
323
- readonly page: "page.page";
324
- readonly pageSize: "page.pageSize";
325
- readonly query: "page.query";
326
- readonly orderBy: "page.orderBy";
327
- };
328
-
329
- /**
330
- * PagedList 响应里各字段的路径(由定义 paged-list.schema.json 生成)。
331
- */
332
- export declare const PAGED_LIST_RESPONSE_PATHS: {
333
- readonly items: "items";
334
- readonly totalRecord: "page.totalRecord";
335
- readonly pageSize: "page.pageSize";
336
- readonly totalPage: "page.totalPage";
337
- };
338
-
339
189
  /** 页码式列表,TItem 是元素类型。 */
340
190
  export declare interface PagedList<TItem = unknown> extends Omit<Generated.PagedList, "items"> {
341
191
  items: TItem[];
@@ -362,7 +212,7 @@ export declare interface PagedListPage {
362
212
  */
363
213
  totalRecord: number;
364
214
  /**
365
- * 每页条数,回显请求值。
215
+ * 每页条数,回显请求值,至少 1。
366
216
  */
367
217
  pageSize: number;
368
218
  /**
@@ -376,11 +226,11 @@ export declare interface PagedListPage {
376
226
  */
377
227
  export declare interface PagedListRequest {
378
228
  /**
379
- * 页码,从 1 开始。
229
+ * 页码,从 1 开始;不带时的含义由接口自己声明。
380
230
  */
381
231
  page?: number;
382
232
  /**
383
- * 每页条数。
233
+ * 每页条数,至少 1;不带时的含义与上限由接口自己声明。
384
234
  */
385
235
  pageSize?: number;
386
236
  /**
@@ -404,10 +254,9 @@ export declare interface SchemaDocument {
404
254
  readonly [keyword: string]: unknown;
405
255
  }
406
256
 
407
- /** 全部定义,键为定义的 $id(即文件名),可整体登记到校验器里。 */
257
+ /** 全部结构定义,键为定义的 $id(即文件名),可整体登记到校验器里。 */
408
258
  export declare const schemas: {
409
259
  readonly "bounded-list.schema.json": SchemaDocument;
410
- readonly "common-error-codes.schema.json": SchemaDocument;
411
260
  readonly "cursor-list-request.schema.json": SchemaDocument;
412
261
  readonly "cursor-list.schema.json": SchemaDocument;
413
262
  readonly "error-body.schema.json": SchemaDocument;
@@ -455,7 +304,7 @@ export declare interface ServiceErrorCode {
455
304
  }
456
305
 
457
306
  /**
458
- * 一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。
307
+ * 一个服务的专有业务码清单。OK 与 HTTP_<数字> 形式的码是结构保留字,不得使用;比较按字节精确进行,不做大小写归一。专有码是否要避开某组通用码由使用方显式检查:把那组码传给参考资源出口的检查函数,不传就不比。
459
308
  */
460
309
  export declare interface ServiceErrorCodes {
461
310
  /**