echoapi-converter 0.0.89 → 0.0.90
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/index.d.ts +24 -2
- package/dist/index.js +528 -53
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -96,11 +96,17 @@ declare class ApifoxToApipost {
|
|
|
96
96
|
serversMap: any;
|
|
97
97
|
modelMap: any;
|
|
98
98
|
foldersMap: any;
|
|
99
|
+
folderNameMap: any;
|
|
99
100
|
apisMap: any;
|
|
100
101
|
dbLinkmap: any;
|
|
101
102
|
commonScripts: any;
|
|
102
103
|
modelIdMap: any;
|
|
103
104
|
envsMap: any;
|
|
105
|
+
apifoxApiIdMap: any;
|
|
106
|
+
config: {
|
|
107
|
+
project_id: string;
|
|
108
|
+
unrelated_id: boolean;
|
|
109
|
+
};
|
|
104
110
|
constructor();
|
|
105
111
|
private validate;
|
|
106
112
|
private clear;
|
|
@@ -120,6 +126,7 @@ declare class ApifoxToApipost {
|
|
|
120
126
|
private completionApiRequestAuth;
|
|
121
127
|
private completionApiRequestParameter;
|
|
122
128
|
private completionApiRequestBody;
|
|
129
|
+
private completionTcpRequestBody;
|
|
123
130
|
private completionApiRequest;
|
|
124
131
|
private completionApiFolder;
|
|
125
132
|
private completionApiTargetMark;
|
|
@@ -131,6 +138,10 @@ declare class ApifoxToApipost {
|
|
|
131
138
|
private completionEventList;
|
|
132
139
|
private completionTestCases;
|
|
133
140
|
private initApis;
|
|
141
|
+
private initWebSocket;
|
|
142
|
+
private completionWebsockets;
|
|
143
|
+
private initSocketIo;
|
|
144
|
+
private completionSocketIo;
|
|
134
145
|
private completionDocs;
|
|
135
146
|
private initDoc;
|
|
136
147
|
private completionTcpClient;
|
|
@@ -139,7 +150,10 @@ declare class ApifoxToApipost {
|
|
|
139
150
|
private completionTcp;
|
|
140
151
|
private initTcp;
|
|
141
152
|
private initTestCase;
|
|
142
|
-
convert(json: any,
|
|
153
|
+
convert(json: any, config?: {
|
|
154
|
+
project_id: string;
|
|
155
|
+
unrelated_id: boolean;
|
|
156
|
+
}): {
|
|
143
157
|
status: "error" | "success";
|
|
144
158
|
message: string;
|
|
145
159
|
data: any;
|
|
@@ -160,6 +174,11 @@ declare class ApifoxcliToApipost {
|
|
|
160
174
|
foldersMap: any;
|
|
161
175
|
commonScripts: any;
|
|
162
176
|
modelIdMap: any;
|
|
177
|
+
config: {
|
|
178
|
+
project_id: string;
|
|
179
|
+
unrelated_id: boolean;
|
|
180
|
+
};
|
|
181
|
+
apifoxApiIdMap: any;
|
|
163
182
|
constructor();
|
|
164
183
|
private validate;
|
|
165
184
|
private clear;
|
|
@@ -191,7 +210,10 @@ declare class ApifoxcliToApipost {
|
|
|
191
210
|
private completionTcpMethodRequest;
|
|
192
211
|
private completionTcpMethod;
|
|
193
212
|
private completionTcp;
|
|
194
|
-
convert(json: any,
|
|
213
|
+
convert(json: any, config?: {
|
|
214
|
+
project_id: string;
|
|
215
|
+
unrelated_id: boolean;
|
|
216
|
+
}): {
|
|
195
217
|
status: "error" | "success";
|
|
196
218
|
message: string;
|
|
197
219
|
data: any;
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var generate__default = /*#__PURE__*/_interopDefaultLegacy(generate);
|
|
|
24
24
|
var JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5);
|
|
25
25
|
var toJsonSchemasecond__default = /*#__PURE__*/_interopDefaultLegacy(toJsonSchemasecond);
|
|
26
26
|
|
|
27
|
-
const DEFAULT_FIELD_TYPE$
|
|
27
|
+
const DEFAULT_FIELD_TYPE$4 = [
|
|
28
28
|
"array",
|
|
29
29
|
"boolean",
|
|
30
30
|
"date",
|
|
@@ -194,18 +194,18 @@ const DEFAULT_BODY = {
|
|
|
194
194
|
binary: {},
|
|
195
195
|
};
|
|
196
196
|
const DEFAULT_DEVELOP_ENUM = [
|
|
197
|
-
"designing",
|
|
198
|
-
"developing",
|
|
199
|
-
"integrating",
|
|
200
|
-
"testing",
|
|
197
|
+
"designing", // 设计中
|
|
198
|
+
"developing", // 开发中
|
|
199
|
+
"integrating", // 联调中
|
|
200
|
+
"testing", // 测试中
|
|
201
201
|
];
|
|
202
|
-
const DEFAULT_COMPLETE_ENUM = ["tested", "released"];
|
|
202
|
+
const DEFAULT_COMPLETE_ENUM = ["tested", "released"]; // 已测完 已发布
|
|
203
203
|
const DEFAULT_EDIT_ENUM = [
|
|
204
|
-
"pending",
|
|
205
|
-
"deprecated",
|
|
206
|
-
"exception",
|
|
204
|
+
"pending", // 待确定
|
|
205
|
+
"deprecated", // 将废弃
|
|
206
|
+
"exception", // 有异常
|
|
207
207
|
];
|
|
208
|
-
const DEFAULT_DISCARD_ENUM = ["obsolete"];
|
|
208
|
+
const DEFAULT_DISCARD_ENUM = ["obsolete"]; // 已废弃
|
|
209
209
|
const DEFAULT_CONTENT_TYPE = ["json", "xml", "html", "binary"];
|
|
210
210
|
const VARS_TYPE_MAP = {
|
|
211
211
|
local: "variables",
|
|
@@ -618,7 +618,10 @@ const getSubstring = (str, length) => {
|
|
|
618
618
|
}
|
|
619
619
|
return str;
|
|
620
620
|
};
|
|
621
|
-
const hexSnowflake = (input) => {
|
|
621
|
+
const hexSnowflake = (input, unrelated) => {
|
|
622
|
+
if (unrelated) {
|
|
623
|
+
return apipostTools.snowflakeId();
|
|
624
|
+
}
|
|
622
625
|
// 将输入转换为BigInt
|
|
623
626
|
let n;
|
|
624
627
|
if (typeof input === 'number') {
|
|
@@ -654,7 +657,7 @@ const hexSnowflake = (input) => {
|
|
|
654
657
|
// 生成一个56bit范围内的数(确保14位16进制)
|
|
655
658
|
const hashed = (n * 0x9e3779b97f4a7c15n) & ((1n << 56n) - 1n);
|
|
656
659
|
// 转成hex并固定为14位长度
|
|
657
|
-
return hashed.toString(16)
|
|
660
|
+
return hashed.toString(16);
|
|
658
661
|
};
|
|
659
662
|
const parseConditionString = (str) => {
|
|
660
663
|
// 定义所有可能的操作符枚举
|
|
@@ -1003,7 +1006,7 @@ const transFieldType = (str) => {
|
|
|
1003
1006
|
const getFidldType = (type) => {
|
|
1004
1007
|
if (!type)
|
|
1005
1008
|
return 'String';
|
|
1006
|
-
if (DEFAULT_FIELD_TYPE$
|
|
1009
|
+
if (DEFAULT_FIELD_TYPE$4.includes(type?.toLowerCase())) {
|
|
1007
1010
|
return transFieldType(type);
|
|
1008
1011
|
}
|
|
1009
1012
|
return 'String';
|
|
@@ -1019,7 +1022,7 @@ const getExampleId = (status) => {
|
|
|
1019
1022
|
return apipostTools.snowflakeId();
|
|
1020
1023
|
}
|
|
1021
1024
|
};
|
|
1022
|
-
const completionParameter = (parameter) => {
|
|
1025
|
+
const completionParameter$1 = (parameter) => {
|
|
1023
1026
|
if (lodash.isArray(parameter)) {
|
|
1024
1027
|
return parameter.map((p) => {
|
|
1025
1028
|
const param = {
|
|
@@ -1140,16 +1143,16 @@ const completionRequestParam = (swaggerApi) => {
|
|
|
1140
1143
|
const parameters = lodash.isArray(swaggerApi?.parameters) ? swaggerApi.parameters : [];
|
|
1141
1144
|
return {
|
|
1142
1145
|
header: {
|
|
1143
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1146
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1144
1147
|
},
|
|
1145
1148
|
query: {
|
|
1146
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1149
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1147
1150
|
},
|
|
1148
1151
|
restful: {
|
|
1149
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'path' && p?.name)),
|
|
1152
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'path' && p?.name)),
|
|
1150
1153
|
},
|
|
1151
1154
|
cookie: {
|
|
1152
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1155
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1153
1156
|
},
|
|
1154
1157
|
body: {
|
|
1155
1158
|
...completionBody(swaggerApi),
|
|
@@ -1428,13 +1431,13 @@ const completionWs2Request = (swaggerApi) => {
|
|
|
1428
1431
|
const parameters = lodash.isArray(swaggerApi?.parameters) ? swaggerApi.parameters : [];
|
|
1429
1432
|
return {
|
|
1430
1433
|
header: {
|
|
1431
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1434
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1432
1435
|
},
|
|
1433
1436
|
query: {
|
|
1434
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1437
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1435
1438
|
},
|
|
1436
1439
|
cookie: {
|
|
1437
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1440
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1438
1441
|
},
|
|
1439
1442
|
};
|
|
1440
1443
|
};
|
|
@@ -1465,13 +1468,13 @@ const completionSocketIoRequest = (swaggerApi) => {
|
|
|
1465
1468
|
const parameters = lodash.isArray(swaggerApi?.parameters) ? swaggerApi.parameters : [];
|
|
1466
1469
|
return {
|
|
1467
1470
|
header: {
|
|
1468
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1471
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1469
1472
|
},
|
|
1470
1473
|
query: {
|
|
1471
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1474
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'query' && p?.name)),
|
|
1472
1475
|
},
|
|
1473
1476
|
cookie: {
|
|
1474
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1477
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1475
1478
|
},
|
|
1476
1479
|
event: {
|
|
1477
1480
|
parameter: lodash.isArray(parameters)
|
|
@@ -1514,10 +1517,10 @@ const completionGraphqlRequest = (swaggerApi) => {
|
|
|
1514
1517
|
const parameters = lodash.isArray(swaggerApi?.parameters) ? swaggerApi.parameters : [];
|
|
1515
1518
|
return {
|
|
1516
1519
|
header: {
|
|
1517
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1520
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'header' && p?.name)),
|
|
1518
1521
|
},
|
|
1519
1522
|
cookie: {
|
|
1520
|
-
parameter: completionParameter(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1523
|
+
parameter: completionParameter$1(parameters.filter(p => p?.in === 'cookie' && p?.name)),
|
|
1521
1524
|
},
|
|
1522
1525
|
pre_tasks: [],
|
|
1523
1526
|
post_tasks: [],
|
|
@@ -4355,6 +4358,199 @@ class ApidocToApipost {
|
|
|
4355
4358
|
}
|
|
4356
4359
|
}
|
|
4357
4360
|
|
|
4361
|
+
const DEFAULT_FIELD_TYPE$3 = ["string", "integer", "boolean", "number", "array"];
|
|
4362
|
+
const completionApiTargetMark = (status) => {
|
|
4363
|
+
if (DEFAULT_DEVELOP_ENUM.includes(status)) {
|
|
4364
|
+
return "1";
|
|
4365
|
+
}
|
|
4366
|
+
if (DEFAULT_COMPLETE_ENUM.includes(status)) {
|
|
4367
|
+
return "2";
|
|
4368
|
+
}
|
|
4369
|
+
if (DEFAULT_EDIT_ENUM.includes(status)) {
|
|
4370
|
+
return "3";
|
|
4371
|
+
}
|
|
4372
|
+
if (DEFAULT_DISCARD_ENUM.includes(status)) {
|
|
4373
|
+
return "4";
|
|
4374
|
+
}
|
|
4375
|
+
return "1";
|
|
4376
|
+
};
|
|
4377
|
+
const completionParameter = (parameter) => {
|
|
4378
|
+
if (lodash.isArray(parameter)) {
|
|
4379
|
+
return parameter?.map((item) => ({
|
|
4380
|
+
param_id: apipostTools.snowflakeId(),
|
|
4381
|
+
description: item?.description || "",
|
|
4382
|
+
field_type: lodash.has(item, "type") && DEFAULT_FIELD_TYPE$3?.includes(item?.type)
|
|
4383
|
+
? item.type.charAt(0).toUpperCase() + item.type.slice(1)
|
|
4384
|
+
: "String",
|
|
4385
|
+
is_checked: lodash.has(item, 'enable') ? (item?.enable ? 1 : -1) : 1,
|
|
4386
|
+
key: item?.name || item?.relatedName || "",
|
|
4387
|
+
value: item?.example || item?.value || "",
|
|
4388
|
+
not_null: item?.required ? 1 : -1,
|
|
4389
|
+
schema: item?.schema || {}
|
|
4390
|
+
}));
|
|
4391
|
+
}
|
|
4392
|
+
return [];
|
|
4393
|
+
};
|
|
4394
|
+
// const websocket2SendType = {
|
|
4395
|
+
// "text":"text",
|
|
4396
|
+
// "json":"json",
|
|
4397
|
+
// "xml":"xml",
|
|
4398
|
+
// "html":"html",
|
|
4399
|
+
// "base64":"base64",
|
|
4400
|
+
// "hexadecimal":"hexadecimal"
|
|
4401
|
+
// }
|
|
4402
|
+
const completionWebsocketTarget = (item, baseInfo, parentInfo) => {
|
|
4403
|
+
const { api } = item || {};
|
|
4404
|
+
let apifoxApi = api;
|
|
4405
|
+
let queryParameter = [];
|
|
4406
|
+
if (lodash.isArray(apifoxApi?.parameters?.query)) {
|
|
4407
|
+
queryParameter = completionParameter(apifoxApi?.parameters?.query);
|
|
4408
|
+
}
|
|
4409
|
+
return {
|
|
4410
|
+
...baseInfo,
|
|
4411
|
+
parent_id: parentInfo?.target_id || "0",
|
|
4412
|
+
target_type: 'websocket2',
|
|
4413
|
+
name: getSubstring(item?.name || apifoxApi?.name, 255) || "Unnamed WS Connection",
|
|
4414
|
+
sort: 0,
|
|
4415
|
+
version: 0,
|
|
4416
|
+
mark_id: completionApiTargetMark(apifoxApi?.status),
|
|
4417
|
+
status: 1,
|
|
4418
|
+
is_changed: -1,
|
|
4419
|
+
is_create: 1,
|
|
4420
|
+
method: '',
|
|
4421
|
+
request: {
|
|
4422
|
+
cookie: {
|
|
4423
|
+
parameter: lodash.isArray(apifoxApi?.parameters?.cookie) ? completionParameter(apifoxApi?.parameters?.cookie) : [],
|
|
4424
|
+
},
|
|
4425
|
+
header: {
|
|
4426
|
+
parameter: lodash.isArray(apifoxApi?.parameters?.header) ? completionParameter(apifoxApi?.parameters?.header) : [],
|
|
4427
|
+
},
|
|
4428
|
+
query: {
|
|
4429
|
+
parameter: queryParameter,
|
|
4430
|
+
},
|
|
4431
|
+
},
|
|
4432
|
+
message: [{
|
|
4433
|
+
name: 'Message',
|
|
4434
|
+
param_id: apipostTools.snowflakeId(),
|
|
4435
|
+
request: {
|
|
4436
|
+
mode: apifoxApi?.requestBody?.messageType || 'text',
|
|
4437
|
+
raw: apifoxApi?.requestBody?.message || '',
|
|
4438
|
+
raw_parameter: [],
|
|
4439
|
+
raw_schema: { type: 'object' },
|
|
4440
|
+
},
|
|
4441
|
+
response: {
|
|
4442
|
+
mode: 'text',
|
|
4443
|
+
raw: '',
|
|
4444
|
+
raw_parameter: [],
|
|
4445
|
+
raw_schema: { type: 'object' },
|
|
4446
|
+
},
|
|
4447
|
+
}],
|
|
4448
|
+
url: apifoxApi?.path || "",
|
|
4449
|
+
description: apifoxApi?.description || "",
|
|
4450
|
+
attribute_info: {},
|
|
4451
|
+
tags: lodash.isArray(apifoxApi?.tags) ? apifoxApi?.tags : [],
|
|
4452
|
+
config: {
|
|
4453
|
+
certificate_verification: apifoxApi?.advancedSettings?.SSLValidate === true ? 1 : -1,
|
|
4454
|
+
information_size: 5,
|
|
4455
|
+
reconnect_num: 5,
|
|
4456
|
+
reconnect_time: 5000,
|
|
4457
|
+
// shake_hands_path: '',
|
|
4458
|
+
shake_hands_timeout: 0,
|
|
4459
|
+
// socket_version: 'v4',
|
|
4460
|
+
},
|
|
4461
|
+
};
|
|
4462
|
+
};
|
|
4463
|
+
const completionSocketIoTarget = (item, baseInfo, parentInfo) => {
|
|
4464
|
+
const { api } = item || {};
|
|
4465
|
+
return {
|
|
4466
|
+
...baseInfo,
|
|
4467
|
+
parent_id: parentInfo?.target_id || "0",
|
|
4468
|
+
target_type: 'socketio',
|
|
4469
|
+
name: getSubstring(item?.name || api?.name, 255) || "Unnamed Socket.IO Session",
|
|
4470
|
+
sort: 0,
|
|
4471
|
+
version: 0,
|
|
4472
|
+
mark_id: completionApiTargetMark(api?.status),
|
|
4473
|
+
status: 1,
|
|
4474
|
+
is_changed: -1,
|
|
4475
|
+
is_create: 1,
|
|
4476
|
+
method: '',
|
|
4477
|
+
request: {
|
|
4478
|
+
cookie: {
|
|
4479
|
+
parameter: lodash.isArray(api?.parameters?.cookie) ? completionParameter(api?.parameters?.cookie) : [],
|
|
4480
|
+
},
|
|
4481
|
+
header: {
|
|
4482
|
+
parameter: lodash.isArray(api?.parameters?.header) ? completionParameter(api?.parameters?.header) : [],
|
|
4483
|
+
},
|
|
4484
|
+
query: {
|
|
4485
|
+
parameter: lodash.isArray(api?.parameters?.query) ? completionParameter(api?.parameters?.query) : [],
|
|
4486
|
+
},
|
|
4487
|
+
event: {
|
|
4488
|
+
parameter: lodash.isArray(api?.events) ? api.events.map(e => {
|
|
4489
|
+
return {
|
|
4490
|
+
description: e?.description || '',
|
|
4491
|
+
field_type: "string",
|
|
4492
|
+
is_checked: 1,
|
|
4493
|
+
key: e?.name || "",
|
|
4494
|
+
value: e?.listen ? "1" : '',
|
|
4495
|
+
not_null: 1,
|
|
4496
|
+
schema: {
|
|
4497
|
+
type: "string"
|
|
4498
|
+
},
|
|
4499
|
+
param_id: apipostTools.snowflakeId()
|
|
4500
|
+
};
|
|
4501
|
+
}) : [],
|
|
4502
|
+
},
|
|
4503
|
+
},
|
|
4504
|
+
message: lodash.isArray(api?.requestBody?.args) ? api.requestBody.args.map((arg, index) => {
|
|
4505
|
+
return {
|
|
4506
|
+
name: `Message${index + 1}`,
|
|
4507
|
+
param_id: apipostTools.snowflakeId(),
|
|
4508
|
+
request: {
|
|
4509
|
+
mode: arg?.type || 'text',
|
|
4510
|
+
raw: arg?.content || '',
|
|
4511
|
+
raw_parameter: [],
|
|
4512
|
+
raw_schema: { type: 'object' },
|
|
4513
|
+
},
|
|
4514
|
+
response: {
|
|
4515
|
+
mode: 'text',
|
|
4516
|
+
raw: '',
|
|
4517
|
+
raw_parameter: [],
|
|
4518
|
+
raw_schema: { type: 'object' },
|
|
4519
|
+
},
|
|
4520
|
+
};
|
|
4521
|
+
}) : [{
|
|
4522
|
+
name: 'Message',
|
|
4523
|
+
param_id: apipostTools.snowflakeId(),
|
|
4524
|
+
request: {
|
|
4525
|
+
mode: 'text',
|
|
4526
|
+
raw: '',
|
|
4527
|
+
raw_parameter: [],
|
|
4528
|
+
raw_schema: { type: 'object' },
|
|
4529
|
+
},
|
|
4530
|
+
response: {
|
|
4531
|
+
mode: 'text',
|
|
4532
|
+
raw: '',
|
|
4533
|
+
raw_parameter: [],
|
|
4534
|
+
raw_schema: { type: 'object' },
|
|
4535
|
+
},
|
|
4536
|
+
}],
|
|
4537
|
+
url: api?.path || "",
|
|
4538
|
+
description: api?.description || '',
|
|
4539
|
+
attribute_info: {},
|
|
4540
|
+
tags: lodash.isArray(api?.tags) ? api?.tags : [],
|
|
4541
|
+
config: {
|
|
4542
|
+
reconnect_num: 5,
|
|
4543
|
+
reconnect_time: 5000,
|
|
4544
|
+
shake_hands_path: api?.advancedSettings?.handshakePath ? api.advancedSettings.handshakePath : '/socket.io',
|
|
4545
|
+
shake_hands_timeout: 0,
|
|
4546
|
+
socket_version: api?.advancedSettings?.clientVersion ? `v${api.advancedSettings.clientVersion}` : 'v4',
|
|
4547
|
+
certificate_verification: api?.advancedSettings?.SSLValidate ? 1 : -1,
|
|
4548
|
+
},
|
|
4549
|
+
ask: api?.requestBody?.ack ? 1 : -1,
|
|
4550
|
+
msg_data: api?.requestBody?.eventName ? api?.requestBody?.eventName : ''
|
|
4551
|
+
};
|
|
4552
|
+
};
|
|
4553
|
+
|
|
4358
4554
|
// @ts-nocheck
|
|
4359
4555
|
const throwResult$1 = (status, message, data = "") => {
|
|
4360
4556
|
return {
|
|
@@ -4473,6 +4669,12 @@ class ApifoxToApipost {
|
|
|
4473
4669
|
writable: true,
|
|
4474
4670
|
value: void 0
|
|
4475
4671
|
});
|
|
4672
|
+
Object.defineProperty(this, "folderNameMap", {
|
|
4673
|
+
enumerable: true,
|
|
4674
|
+
configurable: true,
|
|
4675
|
+
writable: true,
|
|
4676
|
+
value: void 0
|
|
4677
|
+
});
|
|
4476
4678
|
Object.defineProperty(this, "apisMap", {
|
|
4477
4679
|
enumerable: true,
|
|
4478
4680
|
configurable: true,
|
|
@@ -4503,6 +4705,18 @@ class ApifoxToApipost {
|
|
|
4503
4705
|
writable: true,
|
|
4504
4706
|
value: void 0
|
|
4505
4707
|
});
|
|
4708
|
+
Object.defineProperty(this, "apifoxApiIdMap", {
|
|
4709
|
+
enumerable: true,
|
|
4710
|
+
configurable: true,
|
|
4711
|
+
writable: true,
|
|
4712
|
+
value: void 0
|
|
4713
|
+
});
|
|
4714
|
+
Object.defineProperty(this, "config", {
|
|
4715
|
+
enumerable: true,
|
|
4716
|
+
configurable: true,
|
|
4717
|
+
writable: true,
|
|
4718
|
+
value: void 0
|
|
4719
|
+
});
|
|
4506
4720
|
Object.defineProperty(this, "recursionSchema", {
|
|
4507
4721
|
enumerable: true,
|
|
4508
4722
|
configurable: true,
|
|
@@ -4564,6 +4778,10 @@ class ApifoxToApipost {
|
|
|
4564
4778
|
mock_custom_rules: [],
|
|
4565
4779
|
db_link: [],
|
|
4566
4780
|
};
|
|
4781
|
+
this.config = {
|
|
4782
|
+
project_id: "",
|
|
4783
|
+
unrelated_id: false
|
|
4784
|
+
};
|
|
4567
4785
|
this.apis = [];
|
|
4568
4786
|
this.models = [];
|
|
4569
4787
|
this.samples = [];
|
|
@@ -4572,11 +4790,13 @@ class ApifoxToApipost {
|
|
|
4572
4790
|
this.serversMap = {};
|
|
4573
4791
|
this.modelMap = {};
|
|
4574
4792
|
this.foldersMap = { "0": "0" };
|
|
4793
|
+
this.folderNameMap = {};
|
|
4575
4794
|
this.commonScripts = [];
|
|
4576
4795
|
this.apisMap = {};
|
|
4577
4796
|
this.modelIdMap = {};
|
|
4578
4797
|
this.dbLinkmap = {};
|
|
4579
4798
|
this.envsMap = {};
|
|
4799
|
+
this.apifoxApiIdMap = {};
|
|
4580
4800
|
}
|
|
4581
4801
|
validate(json) {
|
|
4582
4802
|
if (lodash.has(json, "apifoxProject")) {
|
|
@@ -4618,6 +4838,10 @@ class ApifoxToApipost {
|
|
|
4618
4838
|
mock_custom_rules: [],
|
|
4619
4839
|
db_link: [],
|
|
4620
4840
|
};
|
|
4841
|
+
this.config = {
|
|
4842
|
+
project_id: "",
|
|
4843
|
+
unrelated_id: false
|
|
4844
|
+
};
|
|
4621
4845
|
this.apis = [];
|
|
4622
4846
|
this.models = [];
|
|
4623
4847
|
this.samples = [];
|
|
@@ -4625,10 +4849,12 @@ class ApifoxToApipost {
|
|
|
4625
4849
|
this.serversMap = {};
|
|
4626
4850
|
this.modelMap = {};
|
|
4627
4851
|
this.foldersMap = { "0": "0" };
|
|
4852
|
+
this.folderNameMap = {};
|
|
4628
4853
|
this.apisMap = {};
|
|
4629
4854
|
this.modelIdMap = {};
|
|
4630
4855
|
this.dbLinkmap = {};
|
|
4631
4856
|
this.envsMap = {};
|
|
4857
|
+
this.apifoxApiIdMap = {};
|
|
4632
4858
|
}
|
|
4633
4859
|
initProject(json, project_id) {
|
|
4634
4860
|
this.project.name = getSubstring(json?.info?.name, 64) || "New Project";
|
|
@@ -4924,7 +5150,7 @@ class ApifoxToApipost {
|
|
|
4924
5150
|
let model_id = apipostTools.snowflakeId();
|
|
4925
5151
|
if (lodash.isString(item?.id)) {
|
|
4926
5152
|
let refId = item.id.split('/').pop();
|
|
4927
|
-
model_id = refId ? hexSnowflake(refId) : model_id;
|
|
5153
|
+
model_id = refId ? hexSnowflake(refId, this.config.unrelated_id) : model_id;
|
|
4928
5154
|
}
|
|
4929
5155
|
if (!lodash.has(this.modelIdMap, model_id)) {
|
|
4930
5156
|
this.modelIdMap[model_id] = model_id;
|
|
@@ -5332,6 +5558,10 @@ class ApifoxToApipost {
|
|
|
5332
5558
|
body["raw"] = requestBody?.example || requestBody?.data || "";
|
|
5333
5559
|
}
|
|
5334
5560
|
}
|
|
5561
|
+
else if (!requestBody?.[type] && requestBody?.data) {
|
|
5562
|
+
body["mode"] = "plain";
|
|
5563
|
+
body["raw"] = requestBody?.data || "";
|
|
5564
|
+
}
|
|
5335
5565
|
return {
|
|
5336
5566
|
mode: "none",
|
|
5337
5567
|
parameter: [],
|
|
@@ -5357,6 +5587,63 @@ class ApifoxToApipost {
|
|
|
5357
5587
|
binary: {},
|
|
5358
5588
|
};
|
|
5359
5589
|
}
|
|
5590
|
+
completionTcpRequestBody(requestBody, type = "type") {
|
|
5591
|
+
if (requestBody && isObject(requestBody)) {
|
|
5592
|
+
let foxMode = requestBody?.[type] || 'text';
|
|
5593
|
+
return {
|
|
5594
|
+
mode: foxMode === "raw" ? "text" : foxMode,
|
|
5595
|
+
"parameter": [
|
|
5596
|
+
{
|
|
5597
|
+
"definition": "",
|
|
5598
|
+
"key": "",
|
|
5599
|
+
"value": "",
|
|
5600
|
+
"description": "",
|
|
5601
|
+
"is_checked": 1,
|
|
5602
|
+
"param_id": "309780acf12016",
|
|
5603
|
+
"static": true,
|
|
5604
|
+
"rules": {
|
|
5605
|
+
"common": "",
|
|
5606
|
+
"content_type": "custom",
|
|
5607
|
+
"custom": "",
|
|
5608
|
+
"fill_type": "",
|
|
5609
|
+
"length": 0,
|
|
5610
|
+
"delimiter": ""
|
|
5611
|
+
}
|
|
5612
|
+
}
|
|
5613
|
+
],
|
|
5614
|
+
"raw": requestBody?.example || "",
|
|
5615
|
+
"raw_parameter": [],
|
|
5616
|
+
"raw_schema": this.recursionSchema(requestBody?.jsonSchema || { type: "object", properties: {} }, this.modelMap)
|
|
5617
|
+
};
|
|
5618
|
+
}
|
|
5619
|
+
return {
|
|
5620
|
+
"mode": "xml",
|
|
5621
|
+
"parameter": [
|
|
5622
|
+
{
|
|
5623
|
+
"definition": "",
|
|
5624
|
+
"key": "",
|
|
5625
|
+
"value": "",
|
|
5626
|
+
"description": "",
|
|
5627
|
+
"is_checked": 1,
|
|
5628
|
+
"param_id": "309780acf12016",
|
|
5629
|
+
"static": true,
|
|
5630
|
+
"rules": {
|
|
5631
|
+
"common": "",
|
|
5632
|
+
"content_type": "custom",
|
|
5633
|
+
"custom": "",
|
|
5634
|
+
"fill_type": "",
|
|
5635
|
+
"length": 0,
|
|
5636
|
+
"delimiter": ""
|
|
5637
|
+
}
|
|
5638
|
+
}
|
|
5639
|
+
],
|
|
5640
|
+
"raw": "",
|
|
5641
|
+
"raw_parameter": [],
|
|
5642
|
+
"raw_schema": {
|
|
5643
|
+
"type": "object"
|
|
5644
|
+
}
|
|
5645
|
+
};
|
|
5646
|
+
}
|
|
5360
5647
|
completionApiRequest(item, requestBody, apiRequestBody) {
|
|
5361
5648
|
return {
|
|
5362
5649
|
auth: this.completionApiRequestAuth(item?.auth),
|
|
@@ -5380,7 +5667,7 @@ class ApifoxToApipost {
|
|
|
5380
5667
|
completionApiFolder(item, parentInfo) {
|
|
5381
5668
|
let target_id = apipostTools.snowflakeId();
|
|
5382
5669
|
if (lodash.has(item, 'id')) {
|
|
5383
|
-
target_id = hexSnowflake(item?.id);
|
|
5670
|
+
target_id = hexSnowflake(item?.id, this.config.unrelated_id);
|
|
5384
5671
|
}
|
|
5385
5672
|
if (item?.id) {
|
|
5386
5673
|
this.foldersMap[item.id] = target_id;
|
|
@@ -5430,7 +5717,7 @@ class ApifoxToApipost {
|
|
|
5430
5717
|
// );
|
|
5431
5718
|
return {
|
|
5432
5719
|
example_id: apipostTools.snowflakeId(),
|
|
5433
|
-
raw: raw ? getBeautifulRaw$1(raw?.data || "") : "",
|
|
5720
|
+
raw: raw ? getBeautifulRaw$1(raw?.data || raw?.content || "") : "",
|
|
5434
5721
|
raw_parameter: [],
|
|
5435
5722
|
expect: {
|
|
5436
5723
|
name: getSubstring(item?.name, 255) || "",
|
|
@@ -5471,7 +5758,13 @@ class ApifoxToApipost {
|
|
|
5471
5758
|
const { api, customHttpRequest } = item || {};
|
|
5472
5759
|
let apifoxApi = api || customHttpRequest;
|
|
5473
5760
|
if (lodash.has(apifoxApi, 'id')) {
|
|
5474
|
-
|
|
5761
|
+
if (lodash.has(this.apifoxApiIdMap, String(apifoxApi?.id))) {
|
|
5762
|
+
baseInfo.target_id = this.apifoxApiIdMap[String(apifoxApi.id)];
|
|
5763
|
+
}
|
|
5764
|
+
else {
|
|
5765
|
+
baseInfo.target_id = hexSnowflake(apifoxApi?.id, this.config.unrelated_id);
|
|
5766
|
+
this.apifoxApiIdMap[String(apifoxApi.id)] = baseInfo.target_id;
|
|
5767
|
+
}
|
|
5475
5768
|
}
|
|
5476
5769
|
if (apifoxApi?.requestBody?.type === 'graphql') {
|
|
5477
5770
|
const request = this.completionApiRequest({
|
|
@@ -5532,7 +5825,7 @@ class ApifoxToApipost {
|
|
|
5532
5825
|
cases?.forEach((caseItem) => {
|
|
5533
5826
|
let sample_id = apipostTools.snowflakeId();
|
|
5534
5827
|
if (lodash.has(caseItem, 'id')) {
|
|
5535
|
-
sample_id = hexSnowflake(caseItem?.id);
|
|
5828
|
+
sample_id = hexSnowflake(caseItem?.id, this.config.unrelated_id);
|
|
5536
5829
|
}
|
|
5537
5830
|
if (!lodash.has(this.apisMap, sample_id)) {
|
|
5538
5831
|
this.apisMap[sample_id] = sample_id;
|
|
@@ -5573,6 +5866,10 @@ class ApifoxToApipost {
|
|
|
5573
5866
|
if (lodash.has(item, "items") && !lodash.has(item, "api")) {
|
|
5574
5867
|
// 这是目录操作
|
|
5575
5868
|
const parent = this.completionApiFolder(item, parentInfo);
|
|
5869
|
+
// 记录以目录名称为key的对象
|
|
5870
|
+
if (!lodash.has(this.folderNameMap, parent.name)) {
|
|
5871
|
+
this.folderNameMap[parent.name] = parent;
|
|
5872
|
+
}
|
|
5576
5873
|
if (!lodash.has(this.apisMap, parent.target_id)) {
|
|
5577
5874
|
this.apisMap[parent.target_id] = parent.target_id;
|
|
5578
5875
|
pre.push(parent);
|
|
@@ -5602,7 +5899,7 @@ class ApifoxToApipost {
|
|
|
5602
5899
|
}
|
|
5603
5900
|
return [];
|
|
5604
5901
|
}
|
|
5605
|
-
completionEventList(steps, parentEventId = '0', result = [], testing_id) {
|
|
5902
|
+
completionEventList(steps, parentEventId = '0', result = [], testing_id, apis = []) {
|
|
5606
5903
|
let sortCounter = 1;
|
|
5607
5904
|
// 记录上一个if类型数据, 主要用来生成else的数据
|
|
5608
5905
|
const ifStack = [];
|
|
@@ -5726,17 +6023,39 @@ class ApifoxToApipost {
|
|
|
5726
6023
|
mappedType = "api";
|
|
5727
6024
|
// 这是接口操作
|
|
5728
6025
|
const base = {
|
|
5729
|
-
target_id: hexSnowflake(item?.bindId),
|
|
6026
|
+
target_id: hexSnowflake(item?.bindId, this.config.unrelated_id),
|
|
5730
6027
|
project_id: this.project.project_id || "",
|
|
5731
6028
|
};
|
|
5732
|
-
//
|
|
6029
|
+
// 判断接口列表中是否有重复id的接口
|
|
5733
6030
|
const targetApi = this.apis.find(i => i?.target_id === base.target_id);
|
|
5734
6031
|
let apiData = {};
|
|
5735
6032
|
if (lodash.isPlainObject(item?.httpApiCase)) {
|
|
5736
|
-
|
|
5737
|
-
name: item?.
|
|
6033
|
+
let httpApiCaseData = {
|
|
6034
|
+
name: item?.name || item?.httpApiCase?.name,
|
|
5738
6035
|
api: { ...item?.httpApiCase, id: item?.httpApiCase?.apiId || item?.bindId }
|
|
5739
|
-
}
|
|
6036
|
+
};
|
|
6037
|
+
const newId = this.apifoxApiIdMap[String(httpApiCaseData.api.id)];
|
|
6038
|
+
// 获取接口列表中的接口
|
|
6039
|
+
const targetApiData = this.apis.find(i => i?.target_id === newId);
|
|
6040
|
+
if (targetApiData !== undefined) {
|
|
6041
|
+
// 补齐url
|
|
6042
|
+
if ((httpApiCaseData.api.path === null || !httpApiCaseData?.api?.path)) {
|
|
6043
|
+
httpApiCaseData.api.path = targetApiData.url;
|
|
6044
|
+
}
|
|
6045
|
+
// 补齐method
|
|
6046
|
+
if ((httpApiCaseData.api.method === null || !httpApiCaseData?.api?.method)) {
|
|
6047
|
+
httpApiCaseData.api.method = targetApiData.method;
|
|
6048
|
+
}
|
|
6049
|
+
// 判断名字是否需要拼接
|
|
6050
|
+
if (!item?.name && targetApiData.name !== httpApiCaseData.name) {
|
|
6051
|
+
httpApiCaseData.name = `${targetApiData.name}(${httpApiCaseData.name})`;
|
|
6052
|
+
}
|
|
6053
|
+
// 补齐body 的mode
|
|
6054
|
+
if (httpApiCaseData?.api?.requestBody && !httpApiCaseData?.api?.requestBody?.type && targetApiData?.body?.mode) {
|
|
6055
|
+
httpApiCaseData.api.requestBody.type = MODE_TYPE2[targetApiData?.body?.mode] || '';
|
|
6056
|
+
}
|
|
6057
|
+
}
|
|
6058
|
+
const targetData = this.completionApiTarget(httpApiCaseData, base);
|
|
5740
6059
|
apiData = targetData;
|
|
5741
6060
|
}
|
|
5742
6061
|
else if (targetApi === undefined) {
|
|
@@ -5758,6 +6077,8 @@ class ApifoxToApipost {
|
|
|
5758
6077
|
};
|
|
5759
6078
|
if (!lodash.has(this.apisMap, apiData.target_id)) {
|
|
5760
6079
|
this.apisMap[apiData.target_id] = apiData.target_id;
|
|
6080
|
+
// 接口列表不存在的接口
|
|
6081
|
+
apis.push(apiData);
|
|
5761
6082
|
}
|
|
5762
6083
|
// 自动同步
|
|
5763
6084
|
if (item?.syncMode === 'SYNC_WITH_API') {
|
|
@@ -5815,7 +6136,7 @@ class ApifoxToApipost {
|
|
|
5815
6136
|
result.push(currentItem);
|
|
5816
6137
|
// 2. 处理子项(steps/children/items)
|
|
5817
6138
|
if (isArray(item.children)) {
|
|
5818
|
-
this.completionEventList(item.children, currentItem.event_id, result, testing_id);
|
|
6139
|
+
this.completionEventList(item.children, currentItem.event_id, result, testing_id, apis);
|
|
5819
6140
|
}
|
|
5820
6141
|
});
|
|
5821
6142
|
return result;
|
|
@@ -5825,7 +6146,7 @@ class ApifoxToApipost {
|
|
|
5825
6146
|
// 1. 处理目录(folder类型)
|
|
5826
6147
|
if ((isArray(item.children) || isArray(item.items)) && !lodash.has(item, 'steps')) {
|
|
5827
6148
|
const folder = {
|
|
5828
|
-
testing_id: hexSnowflake(item?.id), // 如果没有id则生成一个
|
|
6149
|
+
testing_id: hexSnowflake(item?.id, this.config.unrelated_id), // 如果没有id则生成一个
|
|
5829
6150
|
parent_id: parentId,
|
|
5830
6151
|
testing_type: 'folder',
|
|
5831
6152
|
name: item.name || 'Unnamed Folder',
|
|
@@ -5850,14 +6171,15 @@ class ApifoxToApipost {
|
|
|
5850
6171
|
eventList: [],
|
|
5851
6172
|
tags: isArray(item?.tags) ? item.tags : [],
|
|
5852
6173
|
options: item?.options || {},
|
|
5853
|
-
apiTestDataSets: item?.apiTestDataSets || []
|
|
6174
|
+
apiTestDataSets: item?.apiTestDataSets || [],
|
|
6175
|
+
apis: [],
|
|
5854
6176
|
};
|
|
5855
6177
|
let foxEnvironmentId = String(item?.options?.environmentId);
|
|
5856
6178
|
if (lodash.has(this.envsMap, foxEnvironmentId)) {
|
|
5857
6179
|
// 替换新的环境ID
|
|
5858
6180
|
item.options.environmentId = this.envsMap[foxEnvironmentId];
|
|
5859
6181
|
}
|
|
5860
|
-
caseData.eventList = this.completionEventList(item.steps, '0', [], caseData.testing_id);
|
|
6182
|
+
caseData.eventList = this.completionEventList(item.steps, '0', [], caseData.testing_id, caseData.apis);
|
|
5861
6183
|
result.push(caseData);
|
|
5862
6184
|
}
|
|
5863
6185
|
});
|
|
@@ -5869,6 +6191,102 @@ class ApifoxToApipost {
|
|
|
5869
6191
|
this.apis = this.completionApis(root?.items);
|
|
5870
6192
|
}
|
|
5871
6193
|
}
|
|
6194
|
+
initWebSocket(wsCollection) {
|
|
6195
|
+
const root = wsCollection?.[0];
|
|
6196
|
+
if (root?.items && isArray(root?.items)) {
|
|
6197
|
+
this.apis = this.apis.concat(this.completionWebsockets(root?.items));
|
|
6198
|
+
}
|
|
6199
|
+
}
|
|
6200
|
+
completionWebsockets(items, parentInfo) {
|
|
6201
|
+
if (items?.length) {
|
|
6202
|
+
return items?.reduce((pre, item) => {
|
|
6203
|
+
if (lodash.has(item, "items") && !lodash.has(item, "api")) {
|
|
6204
|
+
// 这是目录操作
|
|
6205
|
+
let parent = this.completionApiFolder(item, parentInfo);
|
|
6206
|
+
// 记录以目录名称为key的对象 没有目录才新建目录,有的话直接把ws放到该目录下
|
|
6207
|
+
if (!lodash.has(this.folderNameMap, parent.name)) {
|
|
6208
|
+
this.folderNameMap[parent.name] = parent;
|
|
6209
|
+
}
|
|
6210
|
+
else {
|
|
6211
|
+
parent = this.folderNameMap[parent.name];
|
|
6212
|
+
pre = pre.concat(this.completionWebsockets(item?.items, parent));
|
|
6213
|
+
return pre;
|
|
6214
|
+
}
|
|
6215
|
+
if (!lodash.has(this.apisMap, parent.target_id)) {
|
|
6216
|
+
this.apisMap[parent.target_id] = parent.target_id;
|
|
6217
|
+
pre.push(parent);
|
|
6218
|
+
}
|
|
6219
|
+
else {
|
|
6220
|
+
return pre;
|
|
6221
|
+
// 重复id数据 先忽略
|
|
6222
|
+
}
|
|
6223
|
+
pre = pre.concat(this.completionWebsockets(item?.items, parent));
|
|
6224
|
+
}
|
|
6225
|
+
if (!lodash.has(item, "items") && lodash.has(item, "api")) {
|
|
6226
|
+
// 这是接口操作
|
|
6227
|
+
const base = {
|
|
6228
|
+
target_id: apipostTools.snowflakeId(),
|
|
6229
|
+
project_id: this.project.project_id || "",
|
|
6230
|
+
};
|
|
6231
|
+
const target = completionWebsocketTarget(item, base, parentInfo);
|
|
6232
|
+
if (!lodash.has(this.apisMap, target.target_id)) {
|
|
6233
|
+
this.apisMap[target.target_id] = target.target_id;
|
|
6234
|
+
pre.push(target);
|
|
6235
|
+
}
|
|
6236
|
+
}
|
|
6237
|
+
return pre;
|
|
6238
|
+
}, []);
|
|
6239
|
+
}
|
|
6240
|
+
return [];
|
|
6241
|
+
}
|
|
6242
|
+
initSocketIo(socketIOCollection) {
|
|
6243
|
+
const root = socketIOCollection?.[0];
|
|
6244
|
+
if (root?.items && isArray(root?.items)) {
|
|
6245
|
+
this.apis = this.apis.concat(this.completionSocketIo(root?.items));
|
|
6246
|
+
}
|
|
6247
|
+
}
|
|
6248
|
+
completionSocketIo(items, parentInfo) {
|
|
6249
|
+
if (items?.length) {
|
|
6250
|
+
return items?.reduce((pre, item) => {
|
|
6251
|
+
if (lodash.has(item, "items") && !lodash.has(item, "api")) {
|
|
6252
|
+
// 这是目录操作
|
|
6253
|
+
let parent = this.completionApiFolder(item, parentInfo);
|
|
6254
|
+
// 记录以目录名称为key的对象 没有目录才新建目录,有的话直接把ws放到该目录下
|
|
6255
|
+
if (!lodash.has(this.folderNameMap, parent.name)) {
|
|
6256
|
+
this.folderNameMap[parent.name] = parent;
|
|
6257
|
+
}
|
|
6258
|
+
else {
|
|
6259
|
+
parent = this.folderNameMap[parent.name];
|
|
6260
|
+
pre = pre.concat(this.completionSocketIo(item?.items, parent));
|
|
6261
|
+
return pre;
|
|
6262
|
+
}
|
|
6263
|
+
if (!lodash.has(this.apisMap, parent.target_id)) {
|
|
6264
|
+
this.apisMap[parent.target_id] = parent.target_id;
|
|
6265
|
+
pre.push(parent);
|
|
6266
|
+
}
|
|
6267
|
+
else {
|
|
6268
|
+
return pre;
|
|
6269
|
+
// 重复id数据 先忽略
|
|
6270
|
+
}
|
|
6271
|
+
pre = pre.concat(this.completionSocketIo(item?.items, parent));
|
|
6272
|
+
}
|
|
6273
|
+
if (!lodash.has(item, "items") && lodash.has(item, "api")) {
|
|
6274
|
+
// 这是接口操作
|
|
6275
|
+
const base = {
|
|
6276
|
+
target_id: apipostTools.snowflakeId(),
|
|
6277
|
+
project_id: this.project.project_id || "",
|
|
6278
|
+
};
|
|
6279
|
+
const target = completionSocketIoTarget(item, base, parentInfo);
|
|
6280
|
+
if (!lodash.has(this.apisMap, target.target_id)) {
|
|
6281
|
+
this.apisMap[target.target_id] = target.target_id;
|
|
6282
|
+
pre.push(target);
|
|
6283
|
+
}
|
|
6284
|
+
}
|
|
6285
|
+
return pre;
|
|
6286
|
+
}, []);
|
|
6287
|
+
}
|
|
6288
|
+
return [];
|
|
6289
|
+
}
|
|
5872
6290
|
completionDocs(items) {
|
|
5873
6291
|
if (items?.length) {
|
|
5874
6292
|
return items?.reduce((pre, item) => {
|
|
@@ -5933,13 +6351,32 @@ class ApifoxToApipost {
|
|
|
5933
6351
|
};
|
|
5934
6352
|
}
|
|
5935
6353
|
completionTcpMethodRequest(parameter) {
|
|
6354
|
+
const funcRequest = [];
|
|
6355
|
+
if (isArray(parameter?.dataProcessors)) {
|
|
6356
|
+
lodash.forEach(parameter.dataProcessors, (item) => {
|
|
6357
|
+
if (item?.id == 101) {
|
|
6358
|
+
funcRequest.push({
|
|
6359
|
+
"id": "addCharToPacketEnd",
|
|
6360
|
+
"title": "包尾添加特殊字符",
|
|
6361
|
+
"option": "\\n"
|
|
6362
|
+
});
|
|
6363
|
+
}
|
|
6364
|
+
if (item?.id == 102) {
|
|
6365
|
+
funcRequest.push({
|
|
6366
|
+
"id": "calcLengthToPacketHeader",
|
|
6367
|
+
"title": "计算内容长度并添加到包头(文本)",
|
|
6368
|
+
"option": item?.options?.headerLength || 8
|
|
6369
|
+
});
|
|
6370
|
+
}
|
|
6371
|
+
});
|
|
6372
|
+
}
|
|
5936
6373
|
return {
|
|
5937
|
-
body: this.
|
|
6374
|
+
body: this.completionTcpRequestBody(parameter, "contentType"),
|
|
5938
6375
|
post_tasks: [],
|
|
5939
6376
|
configs: {
|
|
5940
6377
|
charset: "utf8",
|
|
5941
6378
|
func: {
|
|
5942
|
-
request:
|
|
6379
|
+
request: funcRequest,
|
|
5943
6380
|
response: [],
|
|
5944
6381
|
},
|
|
5945
6382
|
},
|
|
@@ -6005,19 +6442,25 @@ class ApifoxToApipost {
|
|
|
6005
6442
|
initTestCase(apiTestCaseCollection) {
|
|
6006
6443
|
// 判断是否有测试用例数据
|
|
6007
6444
|
if (isArray(apiTestCaseCollection) && apiTestCaseCollection.length > 0 && isArray(apiTestCaseCollection[0]?.items)) {
|
|
6008
|
-
this.test_cases = this.completionTestCases(apiTestCaseCollection[0].items);
|
|
6445
|
+
this.test_cases = this.completionTestCases(apiTestCaseCollection[0].items.concat(isArray(apiTestCaseCollection[0]?.children) ? apiTestCaseCollection[0].children : []));
|
|
6009
6446
|
}
|
|
6010
6447
|
}
|
|
6011
|
-
convert(json,
|
|
6448
|
+
convert(json, config = {
|
|
6449
|
+
project_id: "",
|
|
6450
|
+
unrelated_id: false
|
|
6451
|
+
}) {
|
|
6012
6452
|
this.clear();
|
|
6013
6453
|
try {
|
|
6454
|
+
this.config = config;
|
|
6014
6455
|
this.validate(json);
|
|
6015
|
-
this.initProject(json, project_id);
|
|
6456
|
+
this.initProject(json, config?.project_id);
|
|
6016
6457
|
this.initGlobal(json);
|
|
6017
6458
|
this.initModels(json?.schemaCollection);
|
|
6018
6459
|
this.initApis(json?.apiCollection);
|
|
6019
6460
|
this.initDoc(json?.docCollection);
|
|
6020
6461
|
this.initTcp(json?.socketCollection);
|
|
6462
|
+
this.initWebSocket(json?.webSocketCollection);
|
|
6463
|
+
this.initSocketIo(json?.socketIOCollection);
|
|
6021
6464
|
this.initTestCase(json?.apiTestCaseCollection);
|
|
6022
6465
|
const data = {
|
|
6023
6466
|
...this.project,
|
|
@@ -6029,7 +6472,7 @@ class ApifoxToApipost {
|
|
|
6029
6472
|
samples: this.samples,
|
|
6030
6473
|
test_cases: this.test_cases,
|
|
6031
6474
|
};
|
|
6032
|
-
// console.log(JSON.stringify(
|
|
6475
|
+
// console.log(JSON.stringify(this.apis));
|
|
6033
6476
|
return throwResult$1("success", "", data);
|
|
6034
6477
|
}
|
|
6035
6478
|
catch (err) {
|
|
@@ -6153,6 +6596,18 @@ class ApifoxcliToApipost {
|
|
|
6153
6596
|
writable: true,
|
|
6154
6597
|
value: void 0
|
|
6155
6598
|
});
|
|
6599
|
+
Object.defineProperty(this, "config", {
|
|
6600
|
+
enumerable: true,
|
|
6601
|
+
configurable: true,
|
|
6602
|
+
writable: true,
|
|
6603
|
+
value: void 0
|
|
6604
|
+
});
|
|
6605
|
+
Object.defineProperty(this, "apifoxApiIdMap", {
|
|
6606
|
+
enumerable: true,
|
|
6607
|
+
configurable: true,
|
|
6608
|
+
writable: true,
|
|
6609
|
+
value: void 0
|
|
6610
|
+
});
|
|
6156
6611
|
Object.defineProperty(this, "recursionSchema", {
|
|
6157
6612
|
enumerable: true,
|
|
6158
6613
|
configurable: true,
|
|
@@ -6213,6 +6668,10 @@ class ApifoxcliToApipost {
|
|
|
6213
6668
|
mock_custom_rules: [],
|
|
6214
6669
|
db_link: [],
|
|
6215
6670
|
};
|
|
6671
|
+
this.config = {
|
|
6672
|
+
project_id: "",
|
|
6673
|
+
unrelated_id: false
|
|
6674
|
+
};
|
|
6216
6675
|
this.apis = [];
|
|
6217
6676
|
this.eventList = [];
|
|
6218
6677
|
this.models = [];
|
|
@@ -6224,6 +6683,7 @@ class ApifoxcliToApipost {
|
|
|
6224
6683
|
this.foldersMap = { "0": "0" };
|
|
6225
6684
|
this.commonScripts = [];
|
|
6226
6685
|
this.modelIdMap = {};
|
|
6686
|
+
this.apifoxApiIdMap = {};
|
|
6227
6687
|
}
|
|
6228
6688
|
validate(json) {
|
|
6229
6689
|
if (lodash.has(json, "apifoxCli")) {
|
|
@@ -6259,6 +6719,10 @@ class ApifoxcliToApipost {
|
|
|
6259
6719
|
mock_custom_rules: [],
|
|
6260
6720
|
db_link: [],
|
|
6261
6721
|
};
|
|
6722
|
+
this.config = {
|
|
6723
|
+
project_id: "",
|
|
6724
|
+
unrelated_id: false
|
|
6725
|
+
};
|
|
6262
6726
|
this.apis = [];
|
|
6263
6727
|
this.eventList = [];
|
|
6264
6728
|
this.models = [];
|
|
@@ -6268,6 +6732,7 @@ class ApifoxcliToApipost {
|
|
|
6268
6732
|
this.modelMap = {};
|
|
6269
6733
|
this.foldersMap = { "0": "0" };
|
|
6270
6734
|
this.modelIdMap = {};
|
|
6735
|
+
this.apifoxApiIdMap = {};
|
|
6271
6736
|
}
|
|
6272
6737
|
initProject(json, project_id) {
|
|
6273
6738
|
// this.project.testing_type = "testing";
|
|
@@ -6418,7 +6883,7 @@ class ApifoxcliToApipost {
|
|
|
6418
6883
|
if (key) {
|
|
6419
6884
|
// 这是模型操作
|
|
6420
6885
|
// 这里要做Map映射 引用ref替换使用
|
|
6421
|
-
const model_id = hexSnowflake(key);
|
|
6886
|
+
const model_id = hexSnowflake(key, this.config.unrelated_id);
|
|
6422
6887
|
if (!lodash.has(this.modelIdMap, model_id)) {
|
|
6423
6888
|
this.modelIdMap[model_id] = model_id;
|
|
6424
6889
|
}
|
|
@@ -6906,7 +7371,7 @@ class ApifoxcliToApipost {
|
|
|
6906
7371
|
completionApiFolder(item, parentInfo) {
|
|
6907
7372
|
let target_id = apipostTools.snowflakeId();
|
|
6908
7373
|
if (lodash.has(item, 'id')) {
|
|
6909
|
-
target_id = hexSnowflake(item?.id);
|
|
7374
|
+
target_id = hexSnowflake(item?.id, this.config.unrelated_id);
|
|
6910
7375
|
}
|
|
6911
7376
|
if (item?.id) {
|
|
6912
7377
|
this.foldersMap[item.id] = target_id;
|
|
@@ -7018,7 +7483,13 @@ class ApifoxcliToApipost {
|
|
|
7018
7483
|
completionApiTarget(item, baseInfo) {
|
|
7019
7484
|
const { request, response, responseDefinition, requestDefinition, metaInfo } = item || {};
|
|
7020
7485
|
if (lodash.has(metaInfo, 'httpApiId')) {
|
|
7021
|
-
|
|
7486
|
+
if (lodash.has(this.apifoxApiIdMap, String(metaInfo?.httpApiId))) {
|
|
7487
|
+
baseInfo.target_id = this.apifoxApiIdMap[String(metaInfo.httpApiId)];
|
|
7488
|
+
}
|
|
7489
|
+
else {
|
|
7490
|
+
baseInfo.target_id = hexSnowflake(metaInfo?.httpApiId, this.config.unrelated_id);
|
|
7491
|
+
this.apifoxApiIdMap[String(metaInfo.httpApiId)] = baseInfo.target_id;
|
|
7492
|
+
}
|
|
7022
7493
|
}
|
|
7023
7494
|
return {
|
|
7024
7495
|
...baseInfo,
|
|
@@ -7048,7 +7519,7 @@ class ApifoxcliToApipost {
|
|
|
7048
7519
|
return cases?.map((caseItem) => {
|
|
7049
7520
|
let sample_id = apipostTools.snowflakeId();
|
|
7050
7521
|
if (lodash.has(caseItem, 'id')) {
|
|
7051
|
-
sample_id = hexSnowflake(caseItem?.id);
|
|
7522
|
+
sample_id = hexSnowflake(caseItem?.id, this.config.unrelated_id);
|
|
7052
7523
|
}
|
|
7053
7524
|
return {
|
|
7054
7525
|
...baseInfo,
|
|
@@ -7424,11 +7895,15 @@ class ApifoxcliToApipost {
|
|
|
7424
7895
|
}
|
|
7425
7896
|
return [];
|
|
7426
7897
|
}
|
|
7427
|
-
convert(json,
|
|
7898
|
+
convert(json, config = {
|
|
7899
|
+
project_id: "",
|
|
7900
|
+
unrelated_id: false
|
|
7901
|
+
}) {
|
|
7428
7902
|
this.clear();
|
|
7429
7903
|
try {
|
|
7904
|
+
this.config = config;
|
|
7430
7905
|
this.validate(json);
|
|
7431
|
-
this.initProject(json, project_id);
|
|
7906
|
+
this.initProject(json, config?.project_id);
|
|
7432
7907
|
this.initGlobal(json);
|
|
7433
7908
|
this.initModels(json?.dataSchemas);
|
|
7434
7909
|
this.initEventList(json?.item);
|