echoapi-converter 0.0.16 → 0.0.18
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.js +54 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -678,6 +678,18 @@ const fixUrlPath = (url) => {
|
|
|
678
678
|
return url;
|
|
679
679
|
}
|
|
680
680
|
};
|
|
681
|
+
const anyToString = (desc) => {
|
|
682
|
+
if (lodash.isString(desc)) {
|
|
683
|
+
return desc;
|
|
684
|
+
}
|
|
685
|
+
if (lodash.isNumber(desc)) {
|
|
686
|
+
return desc.toString();
|
|
687
|
+
}
|
|
688
|
+
if (lodash.isPlainObject(desc) || isArray(desc)) {
|
|
689
|
+
return JSON.stringify(desc);
|
|
690
|
+
}
|
|
691
|
+
return String(desc);
|
|
692
|
+
};
|
|
681
693
|
|
|
682
694
|
// @ts-nocheck
|
|
683
695
|
class ApipostToSwagger {
|
|
@@ -1523,7 +1535,7 @@ class SwaggerToApipost {
|
|
|
1523
1535
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
1524
1536
|
"", //参数值
|
|
1525
1537
|
not_null: (parameter === null || parameter === void 0 ? void 0 : parameter.required) ? 1 : -1, // 是否为空
|
|
1526
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1538
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1527
1539
|
field_type: getFidldType((_b = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _b === void 0 ? void 0 : _b.type), // 类型
|
|
1528
1540
|
param_id: ATools.snowflakeId(),
|
|
1529
1541
|
});
|
|
@@ -1543,7 +1555,7 @@ class SwaggerToApipost {
|
|
|
1543
1555
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
1544
1556
|
"", //参数值
|
|
1545
1557
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
1546
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1558
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1547
1559
|
field_type: getFidldType((_d = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _d === void 0 ? void 0 : _d.type), // 类型
|
|
1548
1560
|
param_id: ATools.snowflakeId(),
|
|
1549
1561
|
});
|
|
@@ -1563,7 +1575,7 @@ class SwaggerToApipost {
|
|
|
1563
1575
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
1564
1576
|
"", //参数值
|
|
1565
1577
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
1566
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1578
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
1567
1579
|
field_type: getFidldType((_f = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _f === void 0 ? void 0 : _f.type), // 类型
|
|
1568
1580
|
param_id: ATools.snowflakeId(),
|
|
1569
1581
|
});
|
|
@@ -1605,7 +1617,7 @@ class SwaggerToApipost {
|
|
|
1605
1617
|
key: key || "",
|
|
1606
1618
|
value: transExample(item === null || item === void 0 ? void 0 : item.example) || "",
|
|
1607
1619
|
not_null: (item === null || item === void 0 ? void 0 : item.required) ? 1 : -1,
|
|
1608
|
-
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
1620
|
+
description: anyToString(item === null || item === void 0 ? void 0 : item.description) || "",
|
|
1609
1621
|
field_type: lodash.has(item, "type")
|
|
1610
1622
|
? item.type.charAt(0).toUpperCase() + item.type.slice(1)
|
|
1611
1623
|
: "String",
|
|
@@ -2030,7 +2042,7 @@ class SwaggerToApipost {
|
|
|
2030
2042
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
2031
2043
|
"", //参数值
|
|
2032
2044
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
2033
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2045
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2034
2046
|
field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
|
|
2035
2047
|
param_id: ATools.snowflakeId(),
|
|
2036
2048
|
});
|
|
@@ -2050,7 +2062,7 @@ class SwaggerToApipost {
|
|
|
2050
2062
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
2051
2063
|
"", //参数值
|
|
2052
2064
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
2053
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2065
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2054
2066
|
field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
|
|
2055
2067
|
param_id: ATools.snowflakeId(),
|
|
2056
2068
|
});
|
|
@@ -2070,7 +2082,7 @@ class SwaggerToApipost {
|
|
|
2070
2082
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
2071
2083
|
"", //参数值
|
|
2072
2084
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
2073
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2085
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2074
2086
|
field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
|
|
2075
2087
|
param_id: ATools.snowflakeId(),
|
|
2076
2088
|
});
|
|
@@ -2119,7 +2131,7 @@ class SwaggerToApipost {
|
|
|
2119
2131
|
transExample(parameter === null || parameter === void 0 ? void 0 : parameter.default) ||
|
|
2120
2132
|
"", //参数值
|
|
2121
2133
|
not_null: parameter.required ? 1 : -1, // 是否为空
|
|
2122
|
-
description: (parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2134
|
+
description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
|
|
2123
2135
|
field_type: getFidldType(((_g = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _g === void 0 ? void 0 : _g.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type)), // 类型
|
|
2124
2136
|
param_id: ATools.snowflakeId(),
|
|
2125
2137
|
});
|
|
@@ -5090,28 +5102,28 @@ class ThunderToApipost {
|
|
|
5090
5102
|
value: (action, test) => {
|
|
5091
5103
|
let str = "";
|
|
5092
5104
|
if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "res-code")) {
|
|
5093
|
-
str = "const data =
|
|
5105
|
+
str = "const data = pm.response.code";
|
|
5094
5106
|
}
|
|
5095
5107
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "res-body")) {
|
|
5096
|
-
str = "const data =
|
|
5108
|
+
str = "const data = response.raw.responseText";
|
|
5097
5109
|
}
|
|
5098
5110
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "res-time")) {
|
|
5099
|
-
str = "const data =
|
|
5111
|
+
str = "const data = pm.response.responseTime";
|
|
5100
5112
|
}
|
|
5101
5113
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "Content-Type")) {
|
|
5102
|
-
str = "const data =
|
|
5114
|
+
str = "const data = response.headers['content-type']";
|
|
5103
5115
|
}
|
|
5104
5116
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "Content-Length")) {
|
|
5105
|
-
str = `const data =
|
|
5117
|
+
str = `const data = pm.response.responseSize`;
|
|
5106
5118
|
}
|
|
5107
5119
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "Content-Encoding")) {
|
|
5108
|
-
str = `const data =
|
|
5120
|
+
str = `const data = response.headers['content-encoding']`;
|
|
5109
5121
|
}
|
|
5110
5122
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "custom-headers")) {
|
|
5111
|
-
str = `const data =
|
|
5123
|
+
str = `const data = response.headers['${_.toLower(test === null || test === void 0 ? void 0 : test.custom)}']`;
|
|
5112
5124
|
}
|
|
5113
5125
|
else if (lodash.isEqual(test === null || test === void 0 ? void 0 : test.type, "json-query")) {
|
|
5114
|
-
str = `const data = _.get(
|
|
5126
|
+
str = `const data = _.get(response.json,${_.trimStart(test === null || test === void 0 ? void 0 : test.custom, "json.")})`;
|
|
5115
5127
|
}
|
|
5116
5128
|
if (action === "istype") {
|
|
5117
5129
|
return {
|
|
@@ -5156,9 +5168,9 @@ class ThunderToApipost {
|
|
|
5156
5168
|
}
|
|
5157
5169
|
}
|
|
5158
5170
|
|
|
5159
|
-
|
|
5171
|
+
pm.test("${test.action}", function () {
|
|
5160
5172
|
${str}
|
|
5161
|
-
|
|
5173
|
+
pm.expect(isType(data,${_.toUpper(test.value)})).to.true;
|
|
5162
5174
|
});`,
|
|
5163
5175
|
};
|
|
5164
5176
|
}
|
|
@@ -5176,9 +5188,9 @@ class ThunderToApipost {
|
|
|
5176
5188
|
}
|
|
5177
5189
|
return true;
|
|
5178
5190
|
}
|
|
5179
|
-
|
|
5191
|
+
pm.test("${action}", function () {
|
|
5180
5192
|
${str}
|
|
5181
|
-
|
|
5193
|
+
pm.expect(isJSON(data) || typeof data === 'object').to.true;
|
|
5182
5194
|
});`,
|
|
5183
5195
|
};
|
|
5184
5196
|
}
|
|
@@ -5188,9 +5200,9 @@ class ThunderToApipost {
|
|
|
5188
5200
|
id: ATools.snowflakeId(),
|
|
5189
5201
|
name: "Script",
|
|
5190
5202
|
enabled: 1,
|
|
5191
|
-
data: `
|
|
5203
|
+
data: ` pm.test("${action}", function () {
|
|
5192
5204
|
${str}
|
|
5193
|
-
|
|
5205
|
+
pm.expect(_.size(data) === parseInt(${test.value})).to.true;
|
|
5194
5206
|
});`,
|
|
5195
5207
|
};
|
|
5196
5208
|
}
|
|
@@ -5497,11 +5509,30 @@ class ThunderToApipost {
|
|
|
5497
5509
|
],
|
|
5498
5510
|
},
|
|
5499
5511
|
});
|
|
5512
|
+
case "setto":
|
|
5513
|
+
asserts.push({
|
|
5514
|
+
type: "pickVars",
|
|
5515
|
+
id: ATools.snowflakeId(),
|
|
5516
|
+
name: "提取变量",
|
|
5517
|
+
enabled: 1,
|
|
5518
|
+
data: {
|
|
5519
|
+
source: "responseJson",
|
|
5520
|
+
variables: [
|
|
5521
|
+
{
|
|
5522
|
+
param_id: ATools.snowflakeId(),
|
|
5523
|
+
name: lodash.replace(test === null || test === void 0 ? void 0 : test.value, /\{\{(.+?)\}\}/, "$1"),
|
|
5524
|
+
expression: lodash.replace((test === null || test === void 0 ? void 0 : test.custom) || "", "json.", "$.") || "",
|
|
5525
|
+
type: "globalVars",
|
|
5526
|
+
},
|
|
5527
|
+
],
|
|
5528
|
+
},
|
|
5529
|
+
});
|
|
5500
5530
|
break;
|
|
5501
5531
|
}
|
|
5502
5532
|
}
|
|
5503
5533
|
else {
|
|
5504
|
-
|
|
5534
|
+
this.diyScript(test === null || test === void 0 ? void 0 : test.action, test) &&
|
|
5535
|
+
asserts.push(this.diyScript(test === null || test === void 0 ? void 0 : test.action, test));
|
|
5505
5536
|
}
|
|
5506
5537
|
});
|
|
5507
5538
|
return asserts;
|