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/README.md +14 -13
- package/es/Generator.js +29 -195
- package/es/cli.d.ts +3 -1
- package/es/cli.js +63 -23
- package/es/constants.d.ts +0 -1
- package/es/constants.js +1 -2
- package/es/genIndex.js +4 -6
- package/es/genRequest.js +4 -10
- package/es/helpers.d.ts +1 -1
- package/es/helpers.js +1 -8
- package/es/responseDataJsonSchemaHandler.js +1 -1
- package/es/types.d.ts +170 -372
- package/es/types.js +24 -24
- package/es/utils.d.ts +4 -10
- package/es/utils.js +8 -44
- package/lib/Generator.js +29 -195
- package/lib/cli.d.ts +3 -1
- package/lib/cli.js +63 -23
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -2
- package/lib/genIndex.js +4 -6
- package/lib/genRequest.js +4 -10
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +1 -8
- package/lib/responseDataJsonSchemaHandler.js +1 -1
- package/lib/types.d.ts +170 -372
- package/lib/types.js +24 -24
- package/lib/utils.d.ts +4 -10
- package/lib/utils.js +8 -44
- package/package.json +3 -2
- package/es/requestYapiData.d.ts +0 -157
- package/es/requestYapiData.js +0 -1010
- package/lib/requestYapiData.d.ts +0 -157
- package/lib/requestYapiData.js +0 -1010
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
41
|
+
/** Interface ID */
|
|
46
42
|
_id: number;
|
|
47
|
-
/**
|
|
43
|
+
/** Category information (implemented by YTT) */
|
|
48
44
|
_category: OmitStrict<Category, 'list'>;
|
|
49
|
-
/**
|
|
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
|
-
/**
|
|
55
|
+
/** Request method, HEAD and OPTIONS are handled like GET, others like POST */
|
|
60
56
|
method: Method;
|
|
61
|
-
/**
|
|
57
|
+
/** Project ID */
|
|
62
58
|
project_id: number;
|
|
63
|
-
/**
|
|
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
|
-
/**
|
|
84
|
+
/** Type (YApi-X) */
|
|
89
85
|
type?: RequestParamType;
|
|
90
86
|
}>;
|
|
91
|
-
/**
|
|
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
|
-
/**
|
|
97
|
+
/** Type (YApi-X) */
|
|
102
98
|
type?: RequestQueryType;
|
|
103
99
|
}>;
|
|
104
|
-
/**
|
|
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`
|
|
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`
|
|
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
|
-
/**
|
|
125
|
+
/** Creation time (unix timestamp) */
|
|
130
126
|
add_time: number;
|
|
131
|
-
/**
|
|
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
|
-
/**
|
|
158
|
+
/** Creation time (unix timestamp) */
|
|
163
159
|
add_time: number;
|
|
164
|
-
/**
|
|
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
|
-
/**
|
|
311
|
+
/** Category list, corresponding to exported json content */
|
|
316
312
|
export declare type CategoryList = Category[];
|
|
317
|
-
/**
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
603
|
-
|
|
604
|
-
|
|
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
|
-
|
|
613
|
-
/**
|
|
614
|
-
* 代理接口
|
|
615
|
-
*
|
|
616
|
-
* @default /admin-interface/proxy/v0/proxy
|
|
617
|
-
*/
|
|
618
|
-
path?: string;
|
|
619
|
-
};
|
|
438
|
+
outputFilePath?: string;
|
|
620
439
|
/**
|
|
621
|
-
*
|
|
440
|
+
* Set the baseURL for the interface
|
|
622
441
|
*
|
|
623
|
-
* @description
|
|
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: "
|
|
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
|
-
|
|
456
|
+
topImportTemplate?: topImportTemplateType;
|
|
636
457
|
/**
|
|
637
|
-
*
|
|
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
|
-
|
|
646
|
-
/**
|
|
647
|
-
* 请求函数是否需要extra入参
|
|
648
|
-
*
|
|
649
|
-
* @default false
|
|
650
|
-
*/
|
|
651
|
-
requestFunctionExtraParams?: boolean;
|
|
460
|
+
defaultRequestLib?: boolean;
|
|
652
461
|
}
|
|
653
|
-
/**
|
|
654
|
-
export declare type SyntheticalConfig = Partial<
|
|
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 =
|
|
466
|
+
/** Configuration. */
|
|
467
|
+
export declare type Config = ApiConfig;
|
|
662
468
|
/**
|
|
663
|
-
*
|
|
469
|
+
* Request configuration.
|
|
664
470
|
*/
|
|
665
|
-
export interface RequestConfig<
|
|
666
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
488
|
+
/** JSON Schema for request data (only effective when JSON Schema generation is enabled) */
|
|
691
489
|
requestDataJsonSchema: JSONSchema4;
|
|
692
|
-
/**
|
|
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
|
-
/**
|
|
507
|
+
/** All request data, including data and fileData */
|
|
710
508
|
allData: Record<string, any>;
|
|
711
|
-
/**
|
|
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;
|