starlight-server 1.7.5 → 1.7.7
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.
- package/dist/router/helpers.d.ts +3 -3
- package/dist/swagger/factories.d.ts +1 -3
- package/dist/swagger/specification.d.ts +28 -84
- package/dist/swagger/specification.js +1 -0
- package/package.json +15 -15
- package/src/router/helpers.ts +5 -3
- package/src/swagger/factories.ts +1 -1
- package/src/swagger/specification.ts +30 -33
package/dist/router/helpers.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare class RequestHelpers {
|
|
|
7
7
|
readonly request: Request;
|
|
8
8
|
readonly pathParameters: PathParameters;
|
|
9
9
|
constructor(request: Request, pathParameters: PathParameters);
|
|
10
|
-
validatePathParameters<Definition extends Record<string, ValidatorDefinition>>(struct: Definition): import("@anjianshi/utils/validators/base.js").Validated<{
|
|
10
|
+
validatePathParameters<const Definition extends Record<string, ValidatorDefinition>>(struct: Definition): import("@anjianshi/utils/validators/base.js").Validated<{
|
|
11
11
|
readonly type: "struct";
|
|
12
12
|
readonly struct: Definition;
|
|
13
13
|
} extends infer T ? T extends {
|
|
@@ -24,7 +24,7 @@ declare class RequestHelpers {
|
|
|
24
24
|
} : T_1 extends import("@anjianshi/utils/validators/factory.js").RecordDefinition ? Omit<T_1, "record"> & {
|
|
25
25
|
record: import("@anjianshi/utils/validators/factory.js").ValidatorForDefinition<T_1["record"]>;
|
|
26
26
|
} : T_1 : never : never>;
|
|
27
|
-
validateQuery<Definition extends Record<string, ValidatorDefinition>>(struct: Definition): import("@anjianshi/utils/validators/base.js").Validated<{
|
|
27
|
+
validateQuery<const Definition extends Record<string, ValidatorDefinition>>(struct: Definition): import("@anjianshi/utils/validators/base.js").Validated<{
|
|
28
28
|
readonly type: "struct";
|
|
29
29
|
readonly struct: Definition;
|
|
30
30
|
} extends infer T ? T extends {
|
|
@@ -41,7 +41,7 @@ declare class RequestHelpers {
|
|
|
41
41
|
} : T_1 extends import("@anjianshi/utils/validators/factory.js").RecordDefinition ? Omit<T_1, "record"> & {
|
|
42
42
|
record: import("@anjianshi/utils/validators/factory.js").ValidatorForDefinition<T_1["record"]>;
|
|
43
43
|
} : T_1 : never : never>;
|
|
44
|
-
validateBody<Definition extends Record<string, ValidatorDefinition>>(struct: Definition): Promise<import("@anjianshi/utils/validators/base.js").Validated<{
|
|
44
|
+
validateBody<const Definition extends Record<string, ValidatorDefinition>>(struct: Definition): Promise<import("@anjianshi/utils/validators/base.js").Validated<{
|
|
45
45
|
readonly type: "struct";
|
|
46
46
|
readonly struct: Definition;
|
|
47
47
|
} extends infer T ? T extends {
|
|
@@ -21,9 +21,7 @@ export declare function makeDocument(options?: DocumentOptions): OpenAPI;
|
|
|
21
21
|
export declare function makeOperation(options?: OperationOptions): Operation;
|
|
22
22
|
export interface OperationOptions extends Pick<Operation, 'summary' | 'description'> {
|
|
23
23
|
category?: string;
|
|
24
|
-
query?: (Parameter | Reference)[] |
|
|
25
|
-
[name: string]: Schema | Omit<ParameterOptions, 'name'>;
|
|
26
|
-
};
|
|
24
|
+
query?: (Parameter | Reference)[] | Record<string, Schema | Omit<ParameterOptions, 'name'>>;
|
|
27
25
|
/** 用来构建 RequestBody 的选项值,或引用某个 **RequestBody** 的 Reference */
|
|
28
26
|
body?: Parameters<typeof makeBody>[0] | Reference;
|
|
29
27
|
/** 用来构建 Response 的选项值,或引用某个 **Response** 的 Reference */
|
|
@@ -145,9 +145,7 @@ export interface OpenAPI {
|
|
|
145
145
|
* 定义“接口提供方”可能主动请求“接口使用者”的情况,例如做某些通知。
|
|
146
146
|
* “接口使用者”可根据需要有选择性地实现这些 webhook 来接收通知。
|
|
147
147
|
*/
|
|
148
|
-
webhooks?:
|
|
149
|
-
[name: string]: PathItem | Reference;
|
|
150
|
-
};
|
|
148
|
+
webhooks?: Record<string, PathItem | Reference>;
|
|
151
149
|
/** [核心] 定义可重用内容(可通过 $ref 引用这里的内容) */
|
|
152
150
|
components?: Components;
|
|
153
151
|
/**
|
|
@@ -195,9 +193,7 @@ export interface Server extends Extensions {
|
|
|
195
193
|
/** 服务器介绍(CommonMark) */
|
|
196
194
|
description?: string;
|
|
197
195
|
/** 定义可插入到 URL 中的变量列表 */
|
|
198
|
-
variables?:
|
|
199
|
-
[variableName: string]: ServerVariable;
|
|
200
|
-
};
|
|
196
|
+
variables?: Record<string, ServerVariable>;
|
|
201
197
|
}
|
|
202
198
|
/** 服务器 URL 变量定义 */
|
|
203
199
|
export interface ServerVariable extends Extensions {
|
|
@@ -211,45 +207,25 @@ export interface ServerVariable extends Extensions {
|
|
|
211
207
|
/** 可重用内容集合 */
|
|
212
208
|
export interface Components extends Extensions {
|
|
213
209
|
/** 数据格式(可用在请求和响应内容中) */
|
|
214
|
-
schemas?:
|
|
215
|
-
[name: string]: Schema;
|
|
216
|
-
};
|
|
210
|
+
schemas?: Record<string, Schema>;
|
|
217
211
|
/** 响应内容 */
|
|
218
|
-
responses?:
|
|
219
|
-
[name: string]: Response | Reference;
|
|
220
|
-
};
|
|
212
|
+
responses?: Record<string, Response | Reference>;
|
|
221
213
|
/** 请求参数 */
|
|
222
|
-
parameters?:
|
|
223
|
-
[name: string]: Parameter | Reference;
|
|
224
|
-
};
|
|
214
|
+
parameters?: Record<string, Parameter | Reference>;
|
|
225
215
|
/** 范例 */
|
|
226
|
-
examples?:
|
|
227
|
-
[name: string]: Example | Reference;
|
|
228
|
-
};
|
|
216
|
+
examples?: Record<string, Example | Reference>;
|
|
229
217
|
/** 请求体 */
|
|
230
|
-
requestBodies?:
|
|
231
|
-
[name: string]: RequestBody | Reference;
|
|
232
|
-
};
|
|
218
|
+
requestBodies?: Record<string, RequestBody | Reference>;
|
|
233
219
|
/** HTTP Header 定义 */
|
|
234
|
-
headers?:
|
|
235
|
-
[name: string]: Header | Reference;
|
|
236
|
-
};
|
|
220
|
+
headers?: Record<string, Header | Reference>;
|
|
237
221
|
/** 认证方案 */
|
|
238
|
-
securitySchemes?:
|
|
239
|
-
[name: string]: SecurityScheme | Reference;
|
|
240
|
-
};
|
|
222
|
+
securitySchemes?: Record<string, SecurityScheme | Reference>;
|
|
241
223
|
/** 接口关联信息 */
|
|
242
|
-
links?:
|
|
243
|
-
[name: string]: Link | Reference;
|
|
244
|
-
};
|
|
224
|
+
links?: Record<string, Link | Reference>;
|
|
245
225
|
/** 接口回调(接口被调用后,反过来请求“请求发起者”的网址) */
|
|
246
|
-
callbacks?:
|
|
247
|
-
[name: string]: Callback | Reference;
|
|
248
|
-
};
|
|
226
|
+
callbacks?: Record<string, Callback | Reference>;
|
|
249
227
|
/** 对某一接口路径的定义 */
|
|
250
|
-
pathItems?:
|
|
251
|
-
[name: string]: PathItem | Reference;
|
|
252
|
-
};
|
|
228
|
+
pathItems?: Record<string, PathItem | Reference>;
|
|
253
229
|
}
|
|
254
230
|
/**
|
|
255
231
|
* 接口路径列表
|
|
@@ -302,9 +278,7 @@ export interface Operation {
|
|
|
302
278
|
/** 响应内容 */
|
|
303
279
|
responses?: Responses;
|
|
304
280
|
/** 此接口的回调列表。回调 id 须全局唯一。 */
|
|
305
|
-
callbacks?:
|
|
306
|
-
[id: string]: Callback | Reference;
|
|
307
|
-
};
|
|
281
|
+
callbacks?: Record<string, Callback | Reference>;
|
|
308
282
|
/** 接口是否已废弃 */
|
|
309
283
|
deprecated?: boolean;
|
|
310
284
|
/** 此接口的安全要求,代替全局定义的安全要求 */
|
|
@@ -365,9 +339,7 @@ export interface StandardParameter extends BaseParameter {
|
|
|
365
339
|
/** 范例值,不能与 examples 同时存在 */
|
|
366
340
|
example?: unknown;
|
|
367
341
|
/** 一系列范例值,不能与 example 同时存在 */
|
|
368
|
-
examples?:
|
|
369
|
-
[exampleName: string]: Example | Reference;
|
|
370
|
-
};
|
|
342
|
+
examples?: Record<string, Example | Reference>;
|
|
371
343
|
}
|
|
372
344
|
/**
|
|
373
345
|
* 复杂场景的参数:用指定 MIME Type 的格式序列化参数。
|
|
@@ -390,9 +362,7 @@ export interface CustomizeParameter extends BaseParameter {
|
|
|
390
362
|
* 定义序列化方式(MIME Type)和数据内容。
|
|
391
363
|
* 此对象中只能有一个键值对,即一个参数只能有一种序列化方式。
|
|
392
364
|
*/
|
|
393
|
-
content?:
|
|
394
|
-
[MIMEType: string]: MediaType;
|
|
395
|
-
};
|
|
365
|
+
content?: Record<string, MediaType>;
|
|
396
366
|
}
|
|
397
367
|
/** 参数位置 */
|
|
398
368
|
export type ParameterLocation = 'query' | 'header' | 'path' | 'cookie';
|
|
@@ -407,9 +377,7 @@ export interface RequestBody extends Extensions {
|
|
|
407
377
|
* 例如一个接口支持接收 JSON 或 HTML 表单形式的 body。
|
|
408
378
|
* 那么就要定义这样的 content:{ 'application/json': xxx, 'application/x-www-form-urlencoded': xxx }
|
|
409
379
|
*/
|
|
410
|
-
content:
|
|
411
|
-
[MIMEType: string]: MediaType;
|
|
412
|
-
};
|
|
380
|
+
content: Record<string, MediaType>;
|
|
413
381
|
/** 请求体是否必须 */
|
|
414
382
|
required?: boolean;
|
|
415
383
|
}
|
|
@@ -420,9 +388,7 @@ export interface MediaType extends Extensions {
|
|
|
420
388
|
/** 范例值,不能与 examples 同时存在 */
|
|
421
389
|
example?: unknown;
|
|
422
390
|
/** 一系列范例值,不能与 example 同时存在 */
|
|
423
|
-
examples?:
|
|
424
|
-
[exampleName: string]: Example | Reference;
|
|
425
|
-
};
|
|
391
|
+
examples?: Record<string, Example | Reference>;
|
|
426
392
|
/**
|
|
427
393
|
* 为 schema 中的各对象字段补充编码信息。
|
|
428
394
|
* - 仅在 MediaType 出现在 RequestBody 中,且 MIME type 为 `multipart/*` 或 `application/x-www-form-urlencoded` 时有意义。
|
|
@@ -431,9 +397,7 @@ export interface MediaType extends Extensions {
|
|
|
431
397
|
* - 可以理解为 body 的 MIME type 是这两种时,可以通过 encoding 字段在 body 中定义 Parameter。
|
|
432
398
|
* 而其他情况下,body 只能整体定义,总体只拥有一种 MIME Type,不能给其下每个字段单独定义序列化方式。
|
|
433
399
|
*/
|
|
434
|
-
encoding?:
|
|
435
|
-
[schemaProperty: string]: Encoding;
|
|
436
|
-
};
|
|
400
|
+
encoding?: Record<string, Encoding>;
|
|
437
401
|
}
|
|
438
402
|
/**
|
|
439
403
|
* 定义 RequestBody 中单个字段值的编码信息。
|
|
@@ -501,13 +465,9 @@ export interface Response extends Extensions {
|
|
|
501
465
|
* 定义可能的响应内容 MIME Type,及对应的内容格式。
|
|
502
466
|
* 例如一个接口支持返回 JSON 内容,也支持返回 XML(请求时可通过 `Accept` Header 或其他方式指定)。
|
|
503
467
|
*/
|
|
504
|
-
content?:
|
|
505
|
-
[MIMEType: string]: MediaType;
|
|
506
|
-
};
|
|
468
|
+
content?: Record<string, MediaType>;
|
|
507
469
|
/** 列出与此响应内容关联的其他接口(例如返回内容里的 id 字段是另一个接口需要的传参) */
|
|
508
|
-
links?:
|
|
509
|
-
[linkName: string]: Link | Reference;
|
|
510
|
-
};
|
|
470
|
+
links?: Record<string, Link | Reference>;
|
|
511
471
|
}
|
|
512
472
|
/**
|
|
513
473
|
* 定义接口回调(接口被调用后,反过来请求“请求发起者”的网址)。
|
|
@@ -545,9 +505,7 @@ export interface Link extends Extensions {
|
|
|
545
505
|
* - name: 在关联接口处的参数名。可通过 `path.id` 这样的形式指定参数位置(in)
|
|
546
506
|
* - value: 根据当前接口信息生成的参数值。可以是“常量”或“可计算的表达式(Runtime Expression)”
|
|
547
507
|
*/
|
|
548
|
-
parameters?:
|
|
549
|
-
[name: string]: unknown;
|
|
550
|
-
};
|
|
508
|
+
parameters?: Record<string, unknown>;
|
|
551
509
|
/**
|
|
552
510
|
* 当前接口中可作为关联接口的 requestBody 的内容。
|
|
553
511
|
* 值可以是“常量”或“可计算的表达式(Runtime Expression)”。
|
|
@@ -646,13 +604,9 @@ export interface Schema extends Extensions {
|
|
|
646
604
|
/** [type=array] 要求数组里至少有一个元素符合此规范 */
|
|
647
605
|
contains?: Schema | Reference;
|
|
648
606
|
/** [type=object] 对象各字段的规范 */
|
|
649
|
-
properties?:
|
|
650
|
-
[name: string]: Schema | Reference;
|
|
651
|
-
};
|
|
607
|
+
properties?: Record<string, Schema | Reference>;
|
|
652
608
|
/** [type=object] 要求名称与某个 regexp 匹配的字段,值也必须符合对应的 Schema 规范 */
|
|
653
|
-
patternProperties?:
|
|
654
|
-
[regexp: string]: Schema | Reference;
|
|
655
|
-
};
|
|
609
|
+
patternProperties?: Record<string, Schema | Reference>;
|
|
656
610
|
/** [type=object] 指定没被 properties 和 patternProperties 匹配到的字段的规范。 */
|
|
657
611
|
additionalProperties?: Schema | Reference;
|
|
658
612
|
/** [type=object] 要求对象的每个字段名作为字符串都符合此规范 */
|
|
@@ -702,18 +656,12 @@ export interface Schema extends Extensions {
|
|
|
702
656
|
$anchor?: string;
|
|
703
657
|
$dynamicAnchor?: string;
|
|
704
658
|
$dynamicRef?: string;
|
|
705
|
-
$defs?:
|
|
706
|
-
[id: string]: Schema;
|
|
707
|
-
};
|
|
659
|
+
$defs?: Record<string, Schema>;
|
|
708
660
|
$comment?: string;
|
|
709
|
-
dependentSchemas?:
|
|
710
|
-
[propertyName: string]: Schema | Reference;
|
|
711
|
-
};
|
|
661
|
+
dependentSchemas?: Record<string, Schema | Reference>;
|
|
712
662
|
unevaluatedItems?: Schema;
|
|
713
663
|
unevaluatedProperties?: Schema;
|
|
714
|
-
dependencies?:
|
|
715
|
-
[name: string]: Schema | Schema[] | Reference | Reference[];
|
|
716
|
-
};
|
|
664
|
+
dependencies?: Record<string, Schema | Schema[] | Reference | Reference[]>;
|
|
717
665
|
}
|
|
718
666
|
/** 数据类型 */
|
|
719
667
|
export type DataType = 'string' | 'number' | 'integer' | 'boolean' | 'array' | 'object' | 'null';
|
|
@@ -784,16 +732,12 @@ export interface OAuthFlow extends Extensions {
|
|
|
784
732
|
* name 必须是 components.securitySchemes 中定义了的认证方案。
|
|
785
733
|
* value 是方案的配置参数
|
|
786
734
|
*/
|
|
787
|
-
export
|
|
788
|
-
[name: string]: string;
|
|
789
|
-
}
|
|
735
|
+
export type SecurityRequirement = Record<string, string>;
|
|
790
736
|
/**
|
|
791
737
|
* 在规范定义之外,补充额外内容
|
|
792
738
|
* 扩展的 key 需以 'x-' 开头,例如 x-token
|
|
793
739
|
*/
|
|
794
|
-
export
|
|
795
|
-
[key: `x-${string}`]: unknown;
|
|
796
|
-
}
|
|
740
|
+
export type Extensions = Record<`x-${string}`, unknown>;
|
|
797
741
|
/**
|
|
798
742
|
* 因 TypeScript 限制,部分类型无法继承 Extensions,此时可改为继承此类型
|
|
799
743
|
* 但还是应遵守和 Extensions 一样的规范
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "starlight-server",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.7",
|
|
4
4
|
"description": "Simple But Powerful Node.js HTTP Server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -26,25 +26,25 @@
|
|
|
26
26
|
},
|
|
27
27
|
"main": "dist/index.js",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@anjianshi/utils": "^2.2.
|
|
29
|
+
"@anjianshi/utils": "^2.2.5",
|
|
30
30
|
"chalk": "^5.3.0",
|
|
31
|
-
"dayjs": "^1.11.
|
|
32
|
-
"debug": "^4.3.
|
|
31
|
+
"dayjs": "^1.11.12",
|
|
32
|
+
"debug": "^4.3.6",
|
|
33
33
|
"lodash": "^4.17.21",
|
|
34
|
-
"swagger-ui-dist": "^5.
|
|
34
|
+
"swagger-ui-dist": "^5.17.14"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@anjianshi/presets-eslint-node": "^4.0.
|
|
37
|
+
"@anjianshi/presets-eslint-node": "^4.0.8",
|
|
38
38
|
"@anjianshi/presets-prettier": "^3.0.1",
|
|
39
|
-
"@anjianshi/presets-typescript": "^3.2.
|
|
40
|
-
"@types/debug": "^4.1.
|
|
41
|
-
"@types/lodash": "^4.
|
|
42
|
-
"@types/node": "^20.
|
|
43
|
-
"@types/swagger-ui-dist": "^3.30.
|
|
44
|
-
"concurrently": "^8.2.
|
|
45
|
-
"nodemon": "^3.
|
|
46
|
-
"rimraf": "^5.0.
|
|
47
|
-
"tsc-alias": "^1.8.
|
|
39
|
+
"@anjianshi/presets-typescript": "^3.2.2",
|
|
40
|
+
"@types/debug": "^4.1.12",
|
|
41
|
+
"@types/lodash": "^4.17.7",
|
|
42
|
+
"@types/node": "^20.15.0",
|
|
43
|
+
"@types/swagger-ui-dist": "^3.30.5",
|
|
44
|
+
"concurrently": "^8.2.2",
|
|
45
|
+
"nodemon": "^3.1.4",
|
|
46
|
+
"rimraf": "^5.0.10",
|
|
47
|
+
"tsc-alias": "^1.8.10",
|
|
48
48
|
"typescript": "^5.5.4"
|
|
49
49
|
},
|
|
50
50
|
"eslintIgnore": [],
|
package/src/router/helpers.ts
CHANGED
|
@@ -14,7 +14,7 @@ class RequestHelpers {
|
|
|
14
14
|
readonly pathParameters: PathParameters,
|
|
15
15
|
) {}
|
|
16
16
|
|
|
17
|
-
validatePathParameters<Definition extends Record<string, ValidatorDefinition>>(
|
|
17
|
+
validatePathParameters<const Definition extends Record<string, ValidatorDefinition>>(
|
|
18
18
|
struct: Definition,
|
|
19
19
|
) {
|
|
20
20
|
const result = getValidator({ type: 'struct', struct })(
|
|
@@ -25,13 +25,15 @@ class RequestHelpers {
|
|
|
25
25
|
throw new HTTPError(400, result.message)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
validateQuery<Definition extends Record<string, ValidatorDefinition>>(struct: Definition) {
|
|
28
|
+
validateQuery<const Definition extends Record<string, ValidatorDefinition>>(struct: Definition) {
|
|
29
29
|
const result = getValidator({ type: 'struct', struct })('query', this.request.query)
|
|
30
30
|
if (result.success) return result.data
|
|
31
31
|
throw new HTTPError(400, result.message)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
async validateBody<Definition extends Record<string, ValidatorDefinition>>(
|
|
34
|
+
async validateBody<const Definition extends Record<string, ValidatorDefinition>>(
|
|
35
|
+
struct: Definition,
|
|
36
|
+
) {
|
|
35
37
|
const body = await this.request.body.json()
|
|
36
38
|
if (typeof body !== 'object' || body === null || Array.isArray(body))
|
|
37
39
|
throw new HTTPError(400, 'Invalid JSON body, should be an object.')
|
package/src/swagger/factories.ts
CHANGED
|
@@ -69,7 +69,7 @@ export function makeOperation(options: OperationOptions = {}): Operation {
|
|
|
69
69
|
}
|
|
70
70
|
export interface OperationOptions extends Pick<Operation, 'summary' | 'description'> {
|
|
71
71
|
category?: string
|
|
72
|
-
query?: (Parameter | Reference)[] |
|
|
72
|
+
query?: (Parameter | Reference)[] | Record<string, Schema | Omit<ParameterOptions, 'name'>>
|
|
73
73
|
/** 用来构建 RequestBody 的选项值,或引用某个 **RequestBody** 的 Reference */
|
|
74
74
|
body?: Parameters<typeof makeBody>[0] | Reference
|
|
75
75
|
/** 用来构建 Response 的选项值,或引用某个 **Response** 的 Reference */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/consistent-indexed-object-style */
|
|
1
2
|
/**
|
|
2
3
|
* OpenAPI Specification
|
|
3
4
|
* https://swagger.io/specification/
|
|
@@ -146,7 +147,7 @@ export interface OpenAPI {
|
|
|
146
147
|
* 定义“接口提供方”可能主动请求“接口使用者”的情况,例如做某些通知。
|
|
147
148
|
* “接口使用者”可根据需要有选择性地实现这些 webhook 来接收通知。
|
|
148
149
|
*/
|
|
149
|
-
webhooks?:
|
|
150
|
+
webhooks?: Record<string, PathItem | Reference>
|
|
150
151
|
/** [核心] 定义可重用内容(可通过 $ref 引用这里的内容) */
|
|
151
152
|
components?: Components
|
|
152
153
|
/**
|
|
@@ -198,7 +199,7 @@ export interface Server extends Extensions {
|
|
|
198
199
|
/** 服务器介绍(CommonMark) */
|
|
199
200
|
description?: string
|
|
200
201
|
/** 定义可插入到 URL 中的变量列表 */
|
|
201
|
-
variables?:
|
|
202
|
+
variables?: Record<string, ServerVariable>
|
|
202
203
|
}
|
|
203
204
|
|
|
204
205
|
/** 服务器 URL 变量定义 */
|
|
@@ -214,25 +215,25 @@ export interface ServerVariable extends Extensions {
|
|
|
214
215
|
/** 可重用内容集合 */
|
|
215
216
|
export interface Components extends Extensions {
|
|
216
217
|
/** 数据格式(可用在请求和响应内容中) */
|
|
217
|
-
schemas?:
|
|
218
|
+
schemas?: Record<string, Schema>
|
|
218
219
|
/** 响应内容 */
|
|
219
|
-
responses?:
|
|
220
|
+
responses?: Record<string, Response | Reference>
|
|
220
221
|
/** 请求参数 */
|
|
221
|
-
parameters?:
|
|
222
|
+
parameters?: Record<string, Parameter | Reference>
|
|
222
223
|
/** 范例 */
|
|
223
|
-
examples?:
|
|
224
|
+
examples?: Record<string, Example | Reference>
|
|
224
225
|
/** 请求体 */
|
|
225
|
-
requestBodies?:
|
|
226
|
+
requestBodies?: Record<string, RequestBody | Reference>
|
|
226
227
|
/** HTTP Header 定义 */
|
|
227
|
-
headers?:
|
|
228
|
+
headers?: Record<string, Header | Reference>
|
|
228
229
|
/** 认证方案 */
|
|
229
|
-
securitySchemes?:
|
|
230
|
+
securitySchemes?: Record<string, SecurityScheme | Reference>
|
|
230
231
|
/** 接口关联信息 */
|
|
231
|
-
links?:
|
|
232
|
+
links?: Record<string, Link | Reference>
|
|
232
233
|
/** 接口回调(接口被调用后,反过来请求“请求发起者”的网址) */
|
|
233
|
-
callbacks?:
|
|
234
|
+
callbacks?: Record<string, Callback | Reference>
|
|
234
235
|
/** 对某一接口路径的定义 */
|
|
235
|
-
pathItems?:
|
|
236
|
+
pathItems?: Record<string, PathItem | Reference>
|
|
236
237
|
}
|
|
237
238
|
|
|
238
239
|
/**
|
|
@@ -292,7 +293,7 @@ export interface Operation {
|
|
|
292
293
|
/** 响应内容 */
|
|
293
294
|
responses?: Responses
|
|
294
295
|
/** 此接口的回调列表。回调 id 须全局唯一。 */
|
|
295
|
-
callbacks?:
|
|
296
|
+
callbacks?: Record<string, Callback | Reference>
|
|
296
297
|
/** 接口是否已废弃 */
|
|
297
298
|
deprecated?: boolean
|
|
298
299
|
/** 此接口的安全要求,代替全局定义的安全要求 */
|
|
@@ -355,7 +356,7 @@ export interface StandardParameter extends BaseParameter {
|
|
|
355
356
|
/** 范例值,不能与 examples 同时存在 */
|
|
356
357
|
example?: unknown
|
|
357
358
|
/** 一系列范例值,不能与 example 同时存在 */
|
|
358
|
-
examples?:
|
|
359
|
+
examples?: Record<string, Example | Reference>
|
|
359
360
|
}
|
|
360
361
|
/**
|
|
361
362
|
* 复杂场景的参数:用指定 MIME Type 的格式序列化参数。
|
|
@@ -378,7 +379,7 @@ export interface CustomizeParameter extends BaseParameter {
|
|
|
378
379
|
* 定义序列化方式(MIME Type)和数据内容。
|
|
379
380
|
* 此对象中只能有一个键值对,即一个参数只能有一种序列化方式。
|
|
380
381
|
*/
|
|
381
|
-
content?:
|
|
382
|
+
content?: Record<string, MediaType>
|
|
382
383
|
}
|
|
383
384
|
|
|
384
385
|
/** 参数位置 */
|
|
@@ -403,7 +404,7 @@ export interface RequestBody extends Extensions {
|
|
|
403
404
|
* 例如一个接口支持接收 JSON 或 HTML 表单形式的 body。
|
|
404
405
|
* 那么就要定义这样的 content:{ 'application/json': xxx, 'application/x-www-form-urlencoded': xxx }
|
|
405
406
|
*/
|
|
406
|
-
content:
|
|
407
|
+
content: Record<string, MediaType>
|
|
407
408
|
/** 请求体是否必须 */
|
|
408
409
|
required?: boolean
|
|
409
410
|
}
|
|
@@ -415,7 +416,7 @@ export interface MediaType extends Extensions {
|
|
|
415
416
|
/** 范例值,不能与 examples 同时存在 */
|
|
416
417
|
example?: unknown
|
|
417
418
|
/** 一系列范例值,不能与 example 同时存在 */
|
|
418
|
-
examples?:
|
|
419
|
+
examples?: Record<string, Example | Reference>
|
|
419
420
|
/**
|
|
420
421
|
* 为 schema 中的各对象字段补充编码信息。
|
|
421
422
|
* - 仅在 MediaType 出现在 RequestBody 中,且 MIME type 为 `multipart/*` 或 `application/x-www-form-urlencoded` 时有意义。
|
|
@@ -424,7 +425,7 @@ export interface MediaType extends Extensions {
|
|
|
424
425
|
* - 可以理解为 body 的 MIME type 是这两种时,可以通过 encoding 字段在 body 中定义 Parameter。
|
|
425
426
|
* 而其他情况下,body 只能整体定义,总体只拥有一种 MIME Type,不能给其下每个字段单独定义序列化方式。
|
|
426
427
|
*/
|
|
427
|
-
encoding?:
|
|
428
|
+
encoding?: Record<string, Encoding>
|
|
428
429
|
}
|
|
429
430
|
|
|
430
431
|
/**
|
|
@@ -495,9 +496,9 @@ export interface Response extends Extensions {
|
|
|
495
496
|
* 定义可能的响应内容 MIME Type,及对应的内容格式。
|
|
496
497
|
* 例如一个接口支持返回 JSON 内容,也支持返回 XML(请求时可通过 `Accept` Header 或其他方式指定)。
|
|
497
498
|
*/
|
|
498
|
-
content?:
|
|
499
|
+
content?: Record<string, MediaType>
|
|
499
500
|
/** 列出与此响应内容关联的其他接口(例如返回内容里的 id 字段是另一个接口需要的传参) */
|
|
500
|
-
links?:
|
|
501
|
+
links?: Record<string, Link | Reference>
|
|
501
502
|
}
|
|
502
503
|
|
|
503
504
|
/**
|
|
@@ -538,7 +539,7 @@ export interface Link extends Extensions {
|
|
|
538
539
|
* - name: 在关联接口处的参数名。可通过 `path.id` 这样的形式指定参数位置(in)
|
|
539
540
|
* - value: 根据当前接口信息生成的参数值。可以是“常量”或“可计算的表达式(Runtime Expression)”
|
|
540
541
|
*/
|
|
541
|
-
parameters?:
|
|
542
|
+
parameters?: Record<string, unknown>
|
|
542
543
|
/**
|
|
543
544
|
* 当前接口中可作为关联接口的 requestBody 的内容。
|
|
544
545
|
* 值可以是“常量”或“可计算的表达式(Runtime Expression)”。
|
|
@@ -648,9 +649,9 @@ export interface Schema extends Extensions {
|
|
|
648
649
|
contains?: Schema | Reference
|
|
649
650
|
|
|
650
651
|
/** [type=object] 对象各字段的规范 */
|
|
651
|
-
properties?:
|
|
652
|
+
properties?: Record<string, Schema | Reference>
|
|
652
653
|
/** [type=object] 要求名称与某个 regexp 匹配的字段,值也必须符合对应的 Schema 规范 */
|
|
653
|
-
patternProperties?:
|
|
654
|
+
patternProperties?: Record<string, Schema | Reference>
|
|
654
655
|
/** [type=object] 指定没被 properties 和 patternProperties 匹配到的字段的规范。 */
|
|
655
656
|
additionalProperties?: Schema | Reference
|
|
656
657
|
/** [type=object] 要求对象的每个字段名作为字符串都符合此规范 */
|
|
@@ -712,15 +713,15 @@ export interface Schema extends Extensions {
|
|
|
712
713
|
$dynamicAnchor?: string
|
|
713
714
|
// $ref?: string // 类型里不能定义此字段,不然无法区分 Schema 和 Reference
|
|
714
715
|
$dynamicRef?: string
|
|
715
|
-
$defs?:
|
|
716
|
+
$defs?: Record<string, Schema>
|
|
716
717
|
$comment?: string
|
|
717
|
-
dependentSchemas?:
|
|
718
|
+
dependentSchemas?: Record<string, Schema | Reference>
|
|
718
719
|
unevaluatedItems?: Schema
|
|
719
720
|
unevaluatedProperties?: Schema
|
|
720
721
|
|
|
721
722
|
// ----- JSON Schema Validation 规范里的不常用字段 -----
|
|
722
723
|
|
|
723
|
-
dependencies?:
|
|
724
|
+
dependencies?: Record<string, Schema | Schema[] | Reference | Reference[]>
|
|
724
725
|
}
|
|
725
726
|
|
|
726
727
|
/** 数据类型 */
|
|
@@ -803,9 +804,7 @@ export interface OAuthFlow extends Extensions {
|
|
|
803
804
|
* name 必须是 components.securitySchemes 中定义了的认证方案。
|
|
804
805
|
* value 是方案的配置参数
|
|
805
806
|
*/
|
|
806
|
-
export
|
|
807
|
-
[name: string]: string
|
|
808
|
-
}
|
|
807
|
+
export type SecurityRequirement = Record<string, string>
|
|
809
808
|
|
|
810
809
|
// ========= 辅助类型 ==========
|
|
811
810
|
|
|
@@ -813,11 +812,9 @@ export interface SecurityRequirement {
|
|
|
813
812
|
* 在规范定义之外,补充额外内容
|
|
814
813
|
* 扩展的 key 需以 'x-' 开头,例如 x-token
|
|
815
814
|
*/
|
|
816
|
-
export
|
|
817
|
-
[key: `x-${string}`]: unknown
|
|
818
|
-
}
|
|
815
|
+
export type Extensions = Record<`x-${string}`, unknown>
|
|
819
816
|
/**
|
|
820
817
|
* 因 TypeScript 限制,部分类型无法继承 Extensions,此时可改为继承此类型
|
|
821
818
|
* 但还是应遵守和 Extensions 一样的规范
|
|
822
819
|
*/
|
|
823
|
-
export interface LooseExtensions {}
|
|
820
|
+
export interface LooseExtensions {} // eslint-disable-line @typescript-eslint/no-empty-object-type
|