open-api-typescript-request-generator 0.0.1 → 0.0.3

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/lib/types.d.ts CHANGED
@@ -5,134 +5,130 @@ import { OpenAPIV3 } from 'openapi-types';
5
5
  import { LiteralUnion, OmitStrict } from 'vtils/types';
6
6
  import { ParsedPath } from 'path';
7
7
  export declare type requestFunctionTemplateType = (props: RequestFunctionTemplateProps, config?: SyntheticalConfig) => string;
8
- /** 顶部依赖生成模板函数 */
9
- /** 生成器参数 */
10
- export declare type topImportPkgTemplateType = () => string;
11
- export interface GenTemplateType {
12
- requestFunctionTemplate?: requestFunctionTemplateType;
13
- topImportPkgTemplate?: topImportPkgTemplateType;
14
- }
8
+ /** Top dependency generation template function */
9
+ /** Generator parameters */
10
+ export declare type topImportTemplateType = () => string;
15
11
  export interface GeneratorOptions {
16
12
  cwd: string;
17
13
  }
18
- /** 项目信息 */
14
+ /** Project information */
19
15
  export interface Project {
20
16
  /** ID */
21
17
  _id: number;
22
- /** 名称 */
18
+ /** Name */
23
19
  name: string;
24
- /** 描述 */
20
+ /** Description */
25
21
  desc: string;
26
- /** 基本路径 */
22
+ /** Base path */
27
23
  basepath: string;
28
- /** 标签 */
24
+ /** Tags */
29
25
  tag: string[];
30
- /** 环境配置 */
26
+ /** Environment configuration */
31
27
  env: Array<{
32
- /** 环境名称 */
28
+ /** Environment name */
33
29
  name: string;
34
- /** 环境域名 */
30
+ /** Environment domain */
35
31
  domain: string;
36
32
  }>;
37
- /** 项目token */
33
+ /** Project token */
38
34
  token?: string;
39
- /** 项目下分类列表 */
35
+ /** Category list under the project */
40
36
  cat: Category[];
41
37
  components?: object[];
42
38
  }
43
- /** 接口定义 */
39
+ /** Interface definition */
44
40
  export interface Interface {
45
- /** 接口 ID */
41
+ /** Interface ID */
46
42
  _id: number;
47
- /** 所属分类信息(由 YTT 自行实现) */
43
+ /** Category information (implemented by YTT) */
48
44
  _category: OmitStrict<Category, 'list'>;
49
- /** 所属项目信息(由 YTT 自行实现) */
45
+ /** Project information (implemented by YTT) */
50
46
  _project: Project;
51
- /** 接口名称 */
47
+ /** Interface name */
52
48
  title: string;
53
- /** 状态 */
49
+ /** Status */
54
50
  status: LiteralUnion<'done' | 'undone', string>;
55
- /** 接口备注 */
51
+ /** Interface remarks */
56
52
  markdown: string;
57
- /** 请求路径 */
53
+ /** Request path */
58
54
  path: string;
59
- /** 请求方式,HEADOPTIONS 处理与 GET 相似,其余处理与 POST 相似 */
55
+ /** Request method, HEAD and OPTIONS are handled like GET, others like POST */
60
56
  method: Method;
61
- /** 所属项目 id */
57
+ /** Project ID */
62
58
  project_id: number;
63
- /** 所属分类 id */
59
+ /** Category ID */
64
60
  catid: number;
65
- /** 标签列表 */
61
+ /** Tag list */
66
62
  tag: string[];
67
- /** 请求头 */
63
+ /** Request headers */
68
64
  req_headers: Array<{
69
- /** 名称 */
65
+ /** Name */
70
66
  name: string;
71
- /** */
67
+ /** Value */
72
68
  value: string;
73
- /** 备注 */
69
+ /** Description */
74
70
  desc: string;
75
- /** 示例 */
71
+ /** Example */
76
72
  example: string;
77
- /** 是否必需 */
73
+ /** Required */
78
74
  required: Required;
79
75
  }>;
80
- /** 路径参数 */
76
+ /** Path parameters */
81
77
  req_params: Array<{
82
- /** 名称 */
78
+ /** Name */
83
79
  name: string;
84
- /** 备注 */
80
+ /** Description */
85
81
  desc: string;
86
- /** 示例 */
82
+ /** Example */
87
83
  example: string;
88
- /** 类型(YApi-X */
84
+ /** Type (YApi-X) */
89
85
  type?: RequestParamType;
90
86
  }>;
91
- /** GET:请求串 */
87
+ /** GET only: query string */
92
88
  req_query: Array<{
93
- /** 名称 */
89
+ /** Name */
94
90
  name: string;
95
- /** 备注 */
91
+ /** Description */
96
92
  desc: string;
97
- /** 示例 */
93
+ /** Example */
98
94
  example: string;
99
- /** 是否必需 */
95
+ /** Required */
100
96
  required: Required;
101
- /** 类型(YApi-X */
97
+ /** Type (YApi-X) */
102
98
  type?: RequestQueryType;
103
99
  }>;
104
- /** POST:请求内容类型。为 text, file, raw 时不必特殊处理。 */
100
+ /** POST only: request content type. No special handling needed for text, file, raw. */
105
101
  req_body_type: RequestBodyType;
106
- /** `req_body_type = json` 时是否为 json schema */
102
+ /** Whether it is json schema when `req_body_type = json` */
107
103
  req_body_is_json_schema: boolean;
108
- /** `req_body_type = form` 时的请求内容 */
104
+ /** Request content when `req_body_type = form` */
109
105
  req_body_form: Array<{
110
- /** 名称 */
106
+ /** Name */
111
107
  name: string;
112
- /** 类型 */
108
+ /** Type */
113
109
  type: RequestFormItemType;
114
- /** 备注 */
110
+ /** Description */
115
111
  desc: string;
116
- /** 示例 */
112
+ /** Example */
117
113
  example: string;
118
- /** 是否必需 */
114
+ /** Required */
119
115
  required: Required;
120
116
  }>;
121
- /** `req_body_type = json` 时的请求内容 */
117
+ /** Request content when `req_body_type = json` */
122
118
  req_body_other: string;
123
- /** 返回数据类型 */
119
+ /** Response data type */
124
120
  res_body_type: ResponseBodyType;
125
- /** `res_body_type = json` 时是否为 json schema */
121
+ /** Whether it is json schema when `res_body_type = json` */
126
122
  res_body_is_json_schema: boolean;
127
- /** 返回数据 */
123
+ /** Response data */
128
124
  res_body: string;
129
- /** 创建时间(unix时间戳) */
125
+ /** Creation time (unix timestamp) */
130
126
  add_time: number;
131
- /** 更新时间(unix时间戳) */
127
+ /** Update time (unix timestamp) */
132
128
  up_time: number;
133
129
  [key: string]: any;
134
130
  }
135
- /** 接口基本信息 */
131
+ /** Interface basic information */
136
132
  export interface BaseInterfaceInfo {
137
133
  edit_uid: number;
138
134
  status: string;
@@ -147,21 +143,21 @@ export interface BaseInterfaceInfo {
147
143
  uid: number;
148
144
  add_time: number;
149
145
  }
150
- /** 接口列表 */
146
+ /** Interface list */
151
147
  export declare type InterfaceList = Interface[];
152
- /** 分类信息 */
148
+ /** Category information */
153
149
  export interface Category {
154
150
  /** ID */
155
151
  _id: number;
156
- /** 分类名称 */
152
+ /** Category name */
157
153
  name: string;
158
- /** 分类备注 */
154
+ /** Category description */
159
155
  desc: string;
160
- /** 分类接口列表 */
156
+ /** Interface list in this category */
161
157
  list: InterfaceList;
162
- /** 创建时间(unix时间戳) */
158
+ /** Creation time (unix timestamp) */
163
159
  add_time: number;
164
- /** 更新时间(unix时间戳) */
160
+ /** Update time (unix timestamp) */
165
161
  up_time: number;
166
162
  }
167
163
  export interface ChangeCase {
@@ -241,7 +237,7 @@ export interface ChangeCase {
241
237
  */
242
238
  upperCaseFirst: (value: string) => string;
243
239
  }
244
- /** 请求方式 */
240
+ /** Request method */
245
241
  export declare enum Method {
246
242
  GET = "GET",
247
243
  POST = "POST",
@@ -251,482 +247,284 @@ export declare enum Method {
251
247
  OPTIONS = "OPTIONS",
252
248
  PATCH = "PATCH"
253
249
  }
254
- /** 是否必需 */
250
+ /** Required */
255
251
  export declare enum Required {
256
- /** 不必需 */
252
+ /** Not required */
257
253
  false = "0",
258
- /** 必需 */
254
+ /** Required */
259
255
  true = "1"
260
256
  }
261
- /** 请求数据类型 */
257
+ /** Request body type */
262
258
  export declare enum RequestBodyType {
263
- /** 查询字符串 */
259
+ /** Query string */
264
260
  query = "query",
265
- /** 表单 */
261
+ /** Form */
266
262
  form = "form",
267
263
  /** JSON */
268
264
  json = "json",
269
- /** 纯文本 */
265
+ /** Plain text */
270
266
  text = "text",
271
- /** 文件 */
267
+ /** File */
272
268
  file = "file",
273
- /** 原始数据 */
269
+ /** Raw data */
274
270
  raw = "raw",
275
- /** 无请求数据 */
271
+ /** No request data */
276
272
  none = "none"
277
273
  }
278
- /** 请求路径参数类型 */
274
+ /** Request path parameter type */
279
275
  export declare enum RequestParamType {
280
- /** 字符串 */
276
+ /** String */
281
277
  string = "string",
282
- /** 数字 */
278
+ /** Number */
283
279
  number = "number"
284
280
  }
285
- /** 请求查询参数类型 */
281
+ /** Request query parameter type */
286
282
  export declare enum RequestQueryType {
287
- /** 字符串 */
283
+ /** String */
288
284
  string = "string",
289
- /** 数字 */
285
+ /** Number */
290
286
  number = "number"
291
287
  }
292
- /** 请求表单条目类型 */
288
+ /** Request form item type */
293
289
  export declare enum RequestFormItemType {
294
- /** 纯文本 */
290
+ /** Plain text */
295
291
  text = "text",
296
- /** 文件 */
292
+ /** File */
297
293
  file = "file"
298
294
  }
299
- /** 返回数据类型 */
295
+ /** Response body type */
300
296
  export declare enum ResponseBodyType {
301
297
  /** JSON */
302
298
  json = "json",
303
- /** 纯文本 */
299
+ /** Plain text */
304
300
  text = "text",
305
301
  /** XML */
306
302
  xml = "xml",
307
- /** 原始数据 */
303
+ /** Raw data */
308
304
  raw = "raw"
309
305
  /** JSON Schema */
310
306
  }
311
- /** 扩展接口定义 */
307
+ /** Extended interface definition */
312
308
  export interface ExtendedInterface extends Interface {
313
309
  parsedPath: ParsedPath;
314
310
  }
315
- /** 分类列表,对应数据导出的 json 内容 */
311
+ /** Category list, corresponding to exported json content */
316
312
  export declare type CategoryList = Category[];
317
- /** 支持生成 React Hooks 代码的相关配置 */
318
- export interface ReactHooksConfig {
319
- /**
320
- * 是否开启该项功能。
321
- */
322
- enabled: boolean;
323
- /**
324
- * 请求 Hook 函数制造者文件路径。
325
- *
326
- * @default 与 `outputFilePath` 同级目录下的 `makeRequestHook.ts` 文件
327
- * @example 'src/api/makeRequestHook.ts'
328
- */
329
- requestHookMakerFilePath?: string;
330
- /**
331
- * 获取请求 Hook 的名称。
332
- *
333
- * @default `use${changeCase.pascalCase(requestFunctionName)}`
334
- * @param interfaceInfo 接口信息
335
- * @param changeCase 常用的大小写转换函数集合对象
336
- * @returns 请求 Hook 的名称
337
- */
338
- getRequestHookName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
339
- }
340
- /** 支持生成 JSON Schema 的相关配置 */
313
+ /** Configuration for generating JSON Schema */
341
314
  export interface JsonSchemaConfig {
342
315
  /**
343
- * 是否开启该项功能。
316
+ * Whether to enable this feature.
344
317
  */
345
318
  enabled: boolean;
346
319
  }
347
- /** 支持生成注释的相关配置 */
320
+ /** Configuration for generating comments */
348
321
  export interface CommentConfig {
349
322
  /**
350
- * 是否开启该项功能。
323
+ * Whether to enable this feature.
351
324
  *
352
325
  * @default true
353
326
  */
354
327
  enabled?: boolean;
355
328
  /**
356
- * 是否有标题。
329
+ * Whether to include title.
357
330
  *
358
331
  * @default true
359
332
  */
360
333
  title?: boolean;
361
334
  /**
362
- * 是否有分类名称。
335
+ * Whether to include category name.
363
336
  *
364
337
  * @default true
365
338
  */
366
339
  category?: boolean;
367
340
  /**
368
- * 是否有标签。
341
+ * Whether to include tags.
369
342
  *
370
343
  * @default true
371
344
  */
372
345
  tag?: boolean;
373
346
  /**
374
- * 是否有请求头。
347
+ * Whether to include request headers.
375
348
  *
376
349
  * @default true
377
350
  */
378
351
  requestHeader?: boolean;
379
352
  /**
380
- * 是否有更新时间。
353
+ * Whether to include update time.
381
354
  *
382
355
  * @default true
383
356
  */
384
357
  updateTime?: boolean;
385
358
  /**
386
- * 是否为标题、分类名称添加链接。
359
+ * Whether to add links to title and category name.
387
360
  *
388
361
  * @default true
389
362
  */
390
363
  link?: boolean;
391
364
  }
392
365
  /**
393
- * 共享的配置。
366
+ * Shared configuration.
394
367
  */
395
368
  export interface SharedConfig {
396
369
  /**
397
- * 要生成的目标代码类型。
398
- * 默认为 `typescript`,若设为 `javascript`,会将生成的 `.ts` 文件转换为 `.js` + `.d.ts` 文件并删除原 `.ts` 文件。
399
- *
400
- * @default 'typescript'
401
- */
402
- target?: 'typescript' | 'javascript';
403
- /**
404
- * 是否只生成接口请求内容和返回内容的 TypeSript 类型,是则请求文件和请求函数都不会生成。
405
- *
406
- * @default false
407
- */
408
- typesOnly?: boolean;
409
- /**
410
- * 测试环境名称。
411
- *
412
- * **用于获取测试环境域名。**
413
- *
414
- * 获取方式:打开项目 --> `设置` --> `环境配置` --> 点开或新增测试环境 --> 复制测试环境名称。
415
- *
416
- * @example 'dev'
417
- */
418
- devEnvName?: string;
419
- /**
420
- * 生产环境名称。
421
- *
422
- * **用于获取生产环境域名。**
370
+ * Output file path.
423
371
  *
424
- * 获取方式:打开项目 --> `设置` --> `环境配置` --> 点开或新增生产环境 --> 复制生产环境名称。
425
- *
426
- * @example 'prod'
427
- */
428
- prodEnvName?: string;
429
- /**
430
- * 输出文件路径。
431
- *
432
- * 可以是 `相对路径` 或 `绝对路径`。
372
+ * Can be `relative path` or `absolute path`.
433
373
  *
434
374
  * @example 'src/api/index.ts'
435
375
  */
436
376
  outputFilePath?: string;
437
377
  /**
438
- * 请求函数文件路径。
378
+ * Request function file path.
439
379
  *
440
- * @default `outputFilePath` 同级目录下的 `request.ts` 文件
380
+ * @default `request.ts` file in the same directory as `outputFilePath`
441
381
  * @example 'src/api/request.ts'
442
382
  */
443
383
  requestFunctionFilePath?: string;
444
384
  /**
445
- * 如果接口响应的结果是 `JSON` 对象,
446
- * 且我们想要的数据在该对象下,
447
- * 那我们就可将 `dataKey` 设为我们想要的数据对应的键。
448
- *
449
- * 比如该对象为 `{ code: 0, msg: '成功', data: 100 }`,
450
- * 我们想要的数据为 `100`,
451
- * 则我们可将 `dataKey` 设为 `data`。
452
- *
453
- * @example 'data'
385
+ * Configuration for generating JSON Schema.
454
386
  */
455
- dataKey?: string;
456
387
  /**
457
- * 支持生成 React Hooks 代码的相关配置。
458
- */
459
- reactHooks?: ReactHooksConfig;
460
- /**
461
- * 支持生成 JSON Schema 的相关配置。
462
- */
463
- /**
464
- * 支持生成注释的相关配置。
388
+ * Configuration for generating comments.
465
389
  */
466
390
  comment?: CommentConfig;
467
391
  /**
468
- * 预处理接口信息,返回新的接口信息。可返回 false 排除当前接口。
469
- *
470
- * 譬如你想对接口的 `path` 进行某些处理或者想排除某些接口,就可使用该方法。
471
- *
472
- * @example
473
- *
474
- * ```js
475
- * interfaceInfo => {
476
- * interfaceInfo.path = interfaceInfo.path.replace('v1', 'v2')
477
- * return interfaceInfo
478
- * }
479
- * ```
480
- */
481
- preproccessInterface?(interfaceInfo: Interface, changeCase: ChangeCase): Interface | false;
482
- /**
483
- * 获取请求函数的名称。
392
+ * Get the name of the request function.
484
393
  *
485
394
  * @default changeCase.camelCase(interfaceInfo.parsedPath.name)
486
- * @param interfaceInfo 接口信息
487
- * @param changeCase 常用的大小写转换函数集合对象
488
- * @returns 请求函数的名称
395
+ * @param interfaceInfo Interface information
396
+ * @param changeCase Collection of common case conversion functions
397
+ * @returns Name of the request function
489
398
  */
490
399
  getRequestFunctionName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
491
400
  /**
492
- * 获取请求数据类型的名称。
401
+ * Get the name of the request data type.
493
402
  *
494
403
  * @default changeCase.pascalCase(`${requestFunctionName}Request`)
495
- * @param interfaceInfo 接口信息
496
- * @param changeCase 常用的大小写转换函数集合对象
497
- * @returns 请求数据类型的名称
404
+ * @param interfaceInfo Interface information
405
+ * @param changeCase Collection of common case conversion functions
406
+ * @returns Name of the request data type
498
407
  */
499
408
  getRequestDataTypeName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
500
409
  /**
501
- * 获取响应数据类型的名称。
410
+ * Get the name of the response data type.
502
411
  *
503
412
  * @default changeCase.pascalCase(`${requestFunctionName}Response`)
504
- * @param interfaceInfo 接口信息
505
- * @param changeCase 常用的大小写转换函数集合对象
506
- * @returns 响应数据类型的名称
413
+ * @param interfaceInfo Interface information
414
+ * @param changeCase Collection of common case conversion functions
415
+ * @returns Name of the response data type
507
416
  */
508
417
  getResponseDataTypeName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
509
418
  }
510
419
  /**
511
- * 分类的配置。
512
- */
513
- export interface CategoryConfig extends SharedConfig {
514
- /**
515
- * 分类 ID。
516
- *
517
- * 获取方式:打开项目 --> 点开分类 --> 复制浏览器地址栏 `/api/cat_` 后面的数字。
518
- *
519
- * @example 20
520
- */
521
- id: number;
522
- /**
523
- * 过滤接口
524
- */
525
- filter?: ((path: string, id?: number) => boolean) | RegExp | string[];
526
- }
527
- export interface TokenNeed {
528
- /**
529
- * 项目id,与token等效,二选一
530
- *
531
- * 获取方式:打开项目 --> `设置` --> `项目配置` --> 项目ID。
532
- *
533
- * @example '123'
534
- */
535
- projectId?: number;
536
- /**
537
- * 项目的token,与projectId等效,二选一
538
- *
539
- * 获取方式:打开项目 --> `设置` --> `token配置` --> 复制 token。
540
- *
541
- * @example 'e02a47122259d0c1973a9ff81cabb30685d64abc72f39edaa1ac6b6a792a647d'
542
- */
543
- token: string;
544
- }
545
- export interface ProjectIdNeed {
546
- /**
547
- * 项目id,与token等效,二选一
548
- *
549
- * 获取方式:打开项目 --> `设置` --> `项目配置` --> 项目ID。
550
- *
551
- * @example '123'
552
- */
553
- projectId: number;
554
- /**
555
- * 项目的token,与projectId等效,二选一
556
- *
557
- * 获取方式:打开项目 --> `设置` --> `token配置` --> 复制 token。
558
- *
559
- * @example 'e02a47122259d0c1973a9ff81cabb30685d64abc72f39edaa1ac6b6a792a647d'
560
- */
561
- token?: string;
562
- }
563
- /**
564
- * 项目的配置。
420
+ * Server configuration.
565
421
  */
566
- export declare type ProjectConfig = SharedConfig & (ProjectIdNeed | TokenNeed) & {
567
- /**
568
- * 设置接口的baseURL
569
- *
570
- * @description 若要配置使用运行时代码,则增加`[code]:`前缀
571
- ```
572
- 例:
573
- baseURL: "[code]:process.env.BASE_URL" => baseURL:process.env.BASE_URL
574
-
575
- baseURL: "process.env.BASE_URL" => baseURL:"process.env.BASE_URL"
576
- ```
577
- */
578
- baseURL?: ((path: string) => string | undefined) | string;
579
- /**
580
- * 分类列表。
581
- */
582
- categories?: CategoryConfig[];
583
- };
584
- /**
585
- * 服务器的配置。
586
- */
587
- export interface ServerConfig extends SharedConfig, GenTemplateType {
588
- name?: string;
422
+ export interface ApiConfig {
423
+ name: string;
589
424
  configIndex?: number;
590
425
  /**
591
- * 服务地址。若服务类型为 `yapi`,此处填其首页地址;若服务类型为 `swagger`,此处填其 json 地址。
426
+ * Server URL. Enter the swagger json address here.
427
+ * For example, nestjs projects usually use http://localhost:3041/api-json
592
428
  *
593
429
  */
594
430
  serverUrl: string;
595
431
  /**
596
- * 项目列表。
597
- */
598
- project?: ProjectConfig;
599
- /**
600
- * prettier代码格式化配置文件的路径
432
+ * Output file path.
601
433
  *
602
- * @default process.cwd()
603
- */
604
- prettierConfigPath?: string;
605
- /**
606
- * 是否使用默认请求库,关闭后不再生成request.ts
607
- */
608
- defaultRequestLib?: boolean;
609
- /**
610
- * 代理请求模式,所有请求均请求到指定接口
434
+ * Can be `relative path` or `absolute path`.
435
+ *
436
+ * @example 'src/api/index.ts'
611
437
  */
612
- proxyInterface?: {
613
- /**
614
- * 代理接口
615
- *
616
- * @default /admin-interface/proxy/v0/proxy
617
- */
618
- path?: string;
619
- };
438
+ outputFilePath?: string;
620
439
  /**
621
- * 设置接口的baseURL
440
+ * Set the baseURL for the interface
622
441
  *
623
- * @description 若要配置使用运行时代码,则增加`[code]:`前缀
442
+ * @description To configure runtime code, add the `[code]:` prefix
624
443
  ```
625
- 例:
444
+ Example:
626
445
  baseURL: "[code]:process.env.BASE_URL" => baseURL:process.env.BASE_URL
627
446
 
628
- baseURL: "process.env.BASE_URL" => baseURL:"process.env.BASE_URL"
447
+ baseURL: "http://localhost:3000" => baseURL:"http://localhost:3000"
629
448
  ```
630
449
  */
631
450
  baseURL?: ((path: string) => string | undefined) | string;
632
451
  /**
633
- * 过滤接口
452
+ * Define a code snippet at the top of each generated api file
453
+ * For example: import custom request function
454
+ * default: import request from './request'
634
455
  */
635
- filter?: ((path: string, id?: number) => boolean) | RegExp | string[];
456
+ topImportTemplate?: topImportTemplateType;
636
457
  /**
637
- * yapi页面链接地址列表
638
- * 通过url分析出项目id,接口id,分类id
639
- *
640
- @example
641
- ```
642
- `/project/9/interface/api/43 => 项目id:9、接口id: 43`
643
- ```
458
+ * Whether to use the default request library, request.ts will not be generated after disabling, default: true
644
459
  */
645
- yapiUrlList?: string | string[];
646
- /**
647
- * 请求函数是否需要extra入参
648
- *
649
- * @default false
650
- */
651
- requestFunctionExtraParams?: boolean;
460
+ defaultRequestLib?: boolean;
652
461
  }
653
- /** 混合的配置。 */
654
- export declare type SyntheticalConfig = Partial<ServerConfig & ProjectConfig & CategoryConfig & {
655
- mockUrl: string;
656
- devUrl: string;
657
- prodUrl: string;
462
+ /** Combined configuration. */
463
+ export declare type SyntheticalConfig = Partial<ApiConfig & {
658
464
  components: OpenAPIV3.Document['components'];
659
465
  }>;
660
- /** 配置。 */
661
- export declare type Config = ServerConfig;
466
+ /** Configuration. */
467
+ export declare type Config = ApiConfig;
662
468
  /**
663
- * 请求配置。
469
+ * Request configuration.
664
470
  */
665
- export interface RequestConfig<MockUrl extends string = string, DevUrl extends string = string, ProdUrl extends string = string, Path extends string = string, DataKey extends string | undefined = string | undefined, ParamName extends string = string, QueryName extends string = string, RequestDataOptional extends boolean = boolean> {
666
- /** 接口 Mock 地址,结尾无 `/` */
667
- mockUrl: MockUrl;
668
- /** 接口测试环境地址,结尾无 `/` */
669
- devUrl: DevUrl;
670
- /** 接口生产环境地址,结尾无 `/` */
671
- prodUrl: ProdUrl;
672
- /** 接口路径,以 `/` 开头 */
471
+ export interface RequestConfig<Path extends string = string, ParamName extends string = string, QueryName extends string = string, RequestDataOptional extends boolean = boolean> {
472
+ /** Interface path, starting with `/` */
673
473
  path: Path;
674
- /** 请求方法 */
474
+ /** Request method */
675
475
  method: Method;
676
- /** 请求头,除了 Content-Type 的所有头 */
476
+ /** Request headers, all headers except Content-Type */
677
477
  requestHeaders: Record<string, string>;
678
- /** 请求数据类型 */
478
+ /** Request body type */
679
479
  requestBodyType: RequestBodyType;
680
- /** 返回数据类型 */
480
+ /** Response body type */
681
481
  responseBodyType: ResponseBodyType;
682
- /** 数据所在键 */
683
- dataKey: DataKey;
684
- /** 路径参数的名称列表 */
482
+ /** List of path parameter names */
685
483
  paramNames: ParamName[];
686
- /** 查询参数的名称列表 */
484
+ /** List of query parameter names */
687
485
  queryNames: QueryName[];
688
- /** 请求数据是否可选 */
486
+ /** Whether request data is optional */
689
487
  requestDataOptional: RequestDataOptional;
690
- /** 请求数据的 JSON Schema (仅开启了 JSON Schema 生成时生效) */
488
+ /** JSON Schema for request data (only effective when JSON Schema generation is enabled) */
691
489
  requestDataJsonSchema: JSONSchema4;
692
- /** 返回数据的 JSON Schema (仅开启了 JSON Schema 生成时生效) */
490
+ /** JSON Schema for response data (only effective when JSON Schema generation is enabled) */
693
491
  responseDataJsonSchema: JSONSchema4;
694
- /** 请求函数名称 */
492
+ /** Request function name */
695
493
  requestFunctionName: string;
696
494
  }
697
495
  /**
698
- * 请求参数。
496
+ * Request parameters.
699
497
  */
700
498
  export interface RequestFunctionParams extends RequestConfig {
701
- /** 原始数据 */
499
+ /** Raw data */
702
500
  rawData: Record<string, any>;
703
- /** 请求数据,不含文件数据 */
501
+ /** Request data, excluding file data */
704
502
  data: Record<string, any>;
705
- /** 是否有文件数据 */
503
+ /** Whether there is file data */
706
504
  hasFileData: boolean;
707
- /** 请求文件数据 */
505
+ /** Request file data */
708
506
  fileData: Record<string, any>;
709
- /** 所有请求数据,包括 datafileData */
507
+ /** All request data, including data and fileData */
710
508
  allData: Record<string, any>;
711
- /** 获取全部请求数据(包含文件)的 FormData 实例 */
509
+ /** Get FormData instance for all request data (including files) */
712
510
  getFormData: () => FormData;
713
511
  }
714
- /** 请求函数的额外参数 */
512
+ /** Additional parameters of the request function */
715
513
  export declare type RequestFunctionRestArgs<T extends Function> = T extends (payload: any, ...args: infer R) => any ? R : never;
716
- /** 属性定义 */
514
+ /** Property definition */
717
515
  export interface PropDefinition {
718
- /** 属性名称 */
516
+ /** Property name */
719
517
  name: string;
720
- /** 是否必需 */
518
+ /** Required */
721
519
  required: boolean;
722
- /** 类型 */
520
+ /** Type */
723
521
  type: JSONSchema4['type'];
724
- /** 注释 */
522
+ /** Comment */
725
523
  comment: string;
726
524
  }
727
- /** 属性定义列表 */
525
+ /** Property definition list */
728
526
  export declare type PropDefinitions = PropDefinition[];
729
- /** 请求函数体生成模板函数 */
527
+ /** Request function body generation template function */
730
528
  export interface RequestFunctionTemplateProps {
731
529
  baseURL?: string;
732
530
  requestFunctionName: string;