echoapi-converter 0.0.43 → 0.0.45
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 +106 -63
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -771,6 +771,12 @@ const genUrlByQuery = (url, parameter, query_add_equal = 1) => {
|
|
|
771
771
|
newUrl = `${lodash.head(newUrl.split("?"))}${paramsStr ? "?" : ""}${paramsStr}${((_a = urlParse__default["default"](newUrl)) === null || _a === void 0 ? void 0 : _a.hash) || ""}`;
|
|
772
772
|
return newUrl;
|
|
773
773
|
};
|
|
774
|
+
const getSubstring = (str, length) => {
|
|
775
|
+
if (lodash.isString(str)) {
|
|
776
|
+
return str.substring(0, length);
|
|
777
|
+
}
|
|
778
|
+
return str;
|
|
779
|
+
};
|
|
774
780
|
|
|
775
781
|
// @ts-nocheck
|
|
776
782
|
class ApipostToSwagger {
|
|
@@ -1568,8 +1574,8 @@ class SwaggerToApipost {
|
|
|
1568
1574
|
}
|
|
1569
1575
|
}
|
|
1570
1576
|
handlePathV3(path, pathItem, tags) {
|
|
1577
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1571
1578
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1572
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1573
1579
|
let url = path;
|
|
1574
1580
|
for (const method in pathItem) {
|
|
1575
1581
|
const swaggerApi = pathItem[method];
|
|
@@ -1777,8 +1783,8 @@ class SwaggerToApipost {
|
|
|
1777
1783
|
raw: Raw_text,
|
|
1778
1784
|
raw_parameter: raw_parameter,
|
|
1779
1785
|
expect: {
|
|
1780
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1781
|
-
code: status,
|
|
1786
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1787
|
+
code: getSubstring(status, 128),
|
|
1782
1788
|
content_type: "json",
|
|
1783
1789
|
is_default: 1,
|
|
1784
1790
|
mock: "",
|
|
@@ -1793,8 +1799,8 @@ class SwaggerToApipost {
|
|
|
1793
1799
|
raw: Raw_text,
|
|
1794
1800
|
raw_parameter: raw_parameter,
|
|
1795
1801
|
expect: {
|
|
1796
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1797
|
-
code: status,
|
|
1802
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1803
|
+
code: getSubstring(status, 128),
|
|
1798
1804
|
content_type: "json",
|
|
1799
1805
|
is_default: -1,
|
|
1800
1806
|
mock: "",
|
|
@@ -1811,8 +1817,8 @@ class SwaggerToApipost {
|
|
|
1811
1817
|
raw: Raw_text,
|
|
1812
1818
|
raw_parameter: raw_parameter,
|
|
1813
1819
|
expect: {
|
|
1814
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1815
|
-
code: status,
|
|
1820
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1821
|
+
code: getSubstring(status, 128),
|
|
1816
1822
|
content_type: "json",
|
|
1817
1823
|
is_default: -1,
|
|
1818
1824
|
mock: "",
|
|
@@ -1864,8 +1870,8 @@ class SwaggerToApipost {
|
|
|
1864
1870
|
raw: Raw_text,
|
|
1865
1871
|
raw_parameter: [],
|
|
1866
1872
|
expect: {
|
|
1867
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1868
|
-
code: status,
|
|
1873
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1874
|
+
code: getSubstring(status, 128),
|
|
1869
1875
|
content_type: "json",
|
|
1870
1876
|
is_default: status == 200 ? 1 : -1,
|
|
1871
1877
|
mock: "",
|
|
@@ -1896,8 +1902,8 @@ class SwaggerToApipost {
|
|
|
1896
1902
|
raw: Raw_text,
|
|
1897
1903
|
raw_parameter: [],
|
|
1898
1904
|
expect: {
|
|
1899
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1900
|
-
code: status,
|
|
1905
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1906
|
+
code: getSubstring(status, 128),
|
|
1901
1907
|
content_type: "json",
|
|
1902
1908
|
is_default: -1,
|
|
1903
1909
|
mock: "",
|
|
@@ -1921,8 +1927,8 @@ class SwaggerToApipost {
|
|
|
1921
1927
|
raw: Raw_text,
|
|
1922
1928
|
raw_parameter: raw_parameter,
|
|
1923
1929
|
expect: {
|
|
1924
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1925
|
-
code: status,
|
|
1930
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1931
|
+
code: getSubstring(status, 128),
|
|
1926
1932
|
content_type: "json",
|
|
1927
1933
|
is_default: status == 200 ? 1 : -1,
|
|
1928
1934
|
mock: "",
|
|
@@ -1939,8 +1945,8 @@ class SwaggerToApipost {
|
|
|
1939
1945
|
raw: Raw_text,
|
|
1940
1946
|
raw_parameter: raw_parameter,
|
|
1941
1947
|
expect: {
|
|
1942
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
1943
|
-
code: status,
|
|
1948
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
1949
|
+
code: getSubstring(status, 128),
|
|
1944
1950
|
content_type: "json",
|
|
1945
1951
|
is_default: -1,
|
|
1946
1952
|
mock: "",
|
|
@@ -1959,8 +1965,8 @@ class SwaggerToApipost {
|
|
|
1959
1965
|
raw: "",
|
|
1960
1966
|
raw_parameter: [],
|
|
1961
1967
|
expect: {
|
|
1962
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status || "",
|
|
1963
|
-
code: status,
|
|
1968
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status || "", 255),
|
|
1969
|
+
code: getSubstring(status, 128),
|
|
1964
1970
|
content_type: "json",
|
|
1965
1971
|
is_default: -1,
|
|
1966
1972
|
mock: "",
|
|
@@ -1986,8 +1992,8 @@ class SwaggerToApipost {
|
|
|
1986
1992
|
});
|
|
1987
1993
|
}
|
|
1988
1994
|
handlePathsV3(json) {
|
|
1995
|
+
var _a, _b;
|
|
1989
1996
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1990
|
-
var _a, _b;
|
|
1991
1997
|
try {
|
|
1992
1998
|
const paths = ((_a = json === null || json === void 0 ? void 0 : json.openapi) === null || _a === void 0 ? void 0 : _a.paths) || json.paths;
|
|
1993
1999
|
const tags = ((_b = json === null || json === void 0 ? void 0 : json.openapi) === null || _b === void 0 ? void 0 : _b.tags) || json.tags;
|
|
@@ -2019,8 +2025,8 @@ class SwaggerToApipost {
|
|
|
2019
2025
|
}
|
|
2020
2026
|
}
|
|
2021
2027
|
handlePath(path, pathItem, tags) {
|
|
2028
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2022
2029
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2023
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2024
2030
|
let url = path;
|
|
2025
2031
|
url = decodeURI(this.basePath + url);
|
|
2026
2032
|
url = fixUrlPath(url);
|
|
@@ -2257,8 +2263,8 @@ class SwaggerToApipost {
|
|
|
2257
2263
|
raw: Raw_text,
|
|
2258
2264
|
raw_parameter: raw_parameter,
|
|
2259
2265
|
expect: {
|
|
2260
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2261
|
-
code: status,
|
|
2266
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2267
|
+
code: getSubstring(status, 128),
|
|
2262
2268
|
content_type: "json",
|
|
2263
2269
|
is_default: 1,
|
|
2264
2270
|
mock: "",
|
|
@@ -2273,8 +2279,8 @@ class SwaggerToApipost {
|
|
|
2273
2279
|
raw: Raw_text,
|
|
2274
2280
|
raw_parameter: raw_parameter,
|
|
2275
2281
|
expect: {
|
|
2276
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2277
|
-
code: status,
|
|
2282
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2283
|
+
code: getSubstring(status, 128),
|
|
2278
2284
|
content_type: "json",
|
|
2279
2285
|
is_default: -1,
|
|
2280
2286
|
mock: "",
|
|
@@ -2291,8 +2297,8 @@ class SwaggerToApipost {
|
|
|
2291
2297
|
raw: Raw_text,
|
|
2292
2298
|
raw_parameter: raw_parameter,
|
|
2293
2299
|
expect: {
|
|
2294
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2295
|
-
code: status,
|
|
2300
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2301
|
+
code: getSubstring(status, 128),
|
|
2296
2302
|
content_type: "json",
|
|
2297
2303
|
is_default: -1,
|
|
2298
2304
|
mock: "",
|
|
@@ -2326,8 +2332,8 @@ class SwaggerToApipost {
|
|
|
2326
2332
|
raw: Raw_text,
|
|
2327
2333
|
raw_parameter: raw_parameter,
|
|
2328
2334
|
expect: {
|
|
2329
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2330
|
-
code: status,
|
|
2335
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2336
|
+
code: getSubstring(status, 128),
|
|
2331
2337
|
content_type: "json",
|
|
2332
2338
|
is_default: 1,
|
|
2333
2339
|
mock: "",
|
|
@@ -2342,8 +2348,8 @@ class SwaggerToApipost {
|
|
|
2342
2348
|
raw: Raw_text,
|
|
2343
2349
|
raw_parameter: raw_parameter,
|
|
2344
2350
|
expect: {
|
|
2345
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2346
|
-
code: status,
|
|
2351
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2352
|
+
code: getSubstring(status, 128),
|
|
2347
2353
|
content_type: "json",
|
|
2348
2354
|
is_default: -1,
|
|
2349
2355
|
mock: "",
|
|
@@ -2360,8 +2366,8 @@ class SwaggerToApipost {
|
|
|
2360
2366
|
raw: Raw_text,
|
|
2361
2367
|
raw_parameter: raw_parameter,
|
|
2362
2368
|
expect: {
|
|
2363
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2364
|
-
code: status,
|
|
2369
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2370
|
+
code: getSubstring(status, 128),
|
|
2365
2371
|
content_type: "json",
|
|
2366
2372
|
is_default: -1,
|
|
2367
2373
|
mock: "",
|
|
@@ -2386,8 +2392,8 @@ class SwaggerToApipost {
|
|
|
2386
2392
|
raw: "",
|
|
2387
2393
|
raw_parameter: [],
|
|
2388
2394
|
expect: {
|
|
2389
|
-
name: (element === null || element === void 0 ? void 0 : element.description) || status,
|
|
2390
|
-
code: status,
|
|
2395
|
+
name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
|
|
2396
|
+
code: getSubstring(status, 128),
|
|
2391
2397
|
content_type: "json",
|
|
2392
2398
|
is_default: -1,
|
|
2393
2399
|
mock: "",
|
|
@@ -2427,8 +2433,8 @@ class SwaggerToApipost {
|
|
|
2427
2433
|
catch (err) { }
|
|
2428
2434
|
});
|
|
2429
2435
|
}
|
|
2430
|
-
convert(
|
|
2431
|
-
return __awaiter(this,
|
|
2436
|
+
convert(json, options = null) {
|
|
2437
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2432
2438
|
this.clear();
|
|
2433
2439
|
try {
|
|
2434
2440
|
if (options && options instanceof Object) {
|
|
@@ -2755,7 +2761,7 @@ class ApidocToApipost {
|
|
|
2755
2761
|
project_id: this.project.project_id || "",
|
|
2756
2762
|
parent_id: "0",
|
|
2757
2763
|
target_type: "folder",
|
|
2758
|
-
name: (item === null || item === void 0 ? void 0 : item.group) || "New Folder",
|
|
2764
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.group, 255) || "New Folder",
|
|
2759
2765
|
version: 0,
|
|
2760
2766
|
sort: 0,
|
|
2761
2767
|
description: (item === null || item === void 0 ? void 0 : item.groupTitle) || "",
|
|
@@ -2771,7 +2777,7 @@ class ApidocToApipost {
|
|
|
2771
2777
|
project_id: this.project.project_id || "",
|
|
2772
2778
|
parent_id: id || "0",
|
|
2773
2779
|
target_type: "api",
|
|
2774
|
-
name: (item === null || item === void 0 ? void 0 : item.title) || "New HTTP",
|
|
2780
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.title, 255) || "New HTTP",
|
|
2775
2781
|
version: 0,
|
|
2776
2782
|
sort: 0,
|
|
2777
2783
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -2996,8 +3002,8 @@ class ApifoxToApipost {
|
|
|
2996
3002
|
}
|
|
2997
3003
|
initProject(json, project_id) {
|
|
2998
3004
|
var _a, _b;
|
|
2999
|
-
this.project.name = ((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name) || "New Project";
|
|
3000
|
-
this.project.intro = ((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description) || "";
|
|
3005
|
+
this.project.name = getSubstring((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name, 64) || "New Project";
|
|
3006
|
+
this.project.intro = getSubstring((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description, 1024) || "";
|
|
3001
3007
|
this.project.project_id = project_id;
|
|
3002
3008
|
}
|
|
3003
3009
|
completionParameter(parameter) {
|
|
@@ -3566,7 +3572,7 @@ class ApifoxToApipost {
|
|
|
3566
3572
|
project_id: this.project.project_id || "",
|
|
3567
3573
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
3568
3574
|
target_type: "folder",
|
|
3569
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
|
|
3575
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
|
|
3570
3576
|
version: 0,
|
|
3571
3577
|
sort: 0,
|
|
3572
3578
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -3602,9 +3608,9 @@ class ApifoxToApipost {
|
|
|
3602
3608
|
raw: raw ? getBeautifulRaw((raw === null || raw === void 0 ? void 0 : raw.data) || "") : "",
|
|
3603
3609
|
raw_parameter: [],
|
|
3604
3610
|
expect: {
|
|
3605
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "",
|
|
3611
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "",
|
|
3606
3612
|
is_default: index === 0 ? 1 : -1,
|
|
3607
|
-
code: (item === null || item === void 0 ? void 0 : item.code) && lodash.isNumber(item === null || item === void 0 ? void 0 : item.code) ? String(item === null || item === void 0 ? void 0 : item.code) : "",
|
|
3613
|
+
code: (item === null || item === void 0 ? void 0 : item.code) && lodash.isNumber(item === null || item === void 0 ? void 0 : item.code) ? getSubstring(String(item === null || item === void 0 ? void 0 : item.code), 128) : "",
|
|
3608
3614
|
content_type: (DEFAULT_CONTENT_TYPE === null || DEFAULT_CONTENT_TYPE === void 0 ? void 0 : DEFAULT_CONTENT_TYPE.includes(item === null || item === void 0 ? void 0 : item.contentType))
|
|
3609
3615
|
? item === null || item === void 0 ? void 0 : item.contentType
|
|
3610
3616
|
: "json",
|
|
@@ -3643,16 +3649,16 @@ class ApifoxToApipost {
|
|
|
3643
3649
|
if (((_a = api === null || api === void 0 ? void 0 : api.requestBody) === null || _a === void 0 ? void 0 : _a.type) === 'graphql') {
|
|
3644
3650
|
const request = this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody);
|
|
3645
3651
|
const body = this.completionGraphqlRequestBody(api === null || api === void 0 ? void 0 : api.requestBody);
|
|
3646
|
-
return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "graphql", name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), request: Object.assign(Object.assign({}, lodash.omit(request, ['body', 'query', 'restful'])), { body }), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
|
|
3652
|
+
return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "graphql", name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), request: Object.assign(Object.assign({}, lodash.omit(request, ['body', 'query', 'restful'])), { body }), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
|
|
3647
3653
|
}
|
|
3648
|
-
return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "api", name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", method: (api === null || api === void 0 ? void 0 : api.method) ? (_b = api === null || api === void 0 ? void 0 : api.method) === null || _b === void 0 ? void 0 : _b.toUpperCase() : "GET", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), protocol: "http/1.1", request: this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
|
|
3654
|
+
return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "api", name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", method: (api === null || api === void 0 ? void 0 : api.method) ? (_b = api === null || api === void 0 ? void 0 : api.method) === null || _b === void 0 ? void 0 : _b.toUpperCase() : "GET", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), protocol: "http/1.1", request: this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
|
|
3649
3655
|
}
|
|
3650
3656
|
completionApiSample(item, baseInfo) {
|
|
3651
3657
|
const { api } = item || {};
|
|
3652
3658
|
const { cases } = api || {};
|
|
3653
3659
|
return cases === null || cases === void 0 ? void 0 : cases.map((caseItem) => {
|
|
3654
3660
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
3655
|
-
return Object.assign(Object.assign({}, baseInfo), { created_at: 0, method: (api === null || api === void 0 ? void 0 : api.method) ? (_a = api === null || api === void 0 ? void 0 : api.method) === null || _a === void 0 ? void 0 : _a.toUpperCase() : "GET", name: (caseItem === null || caseItem === void 0 ? void 0 : caseItem.name) || "New Test Case", parent_id: "0", protocol: "http/1.1", request: this.completionApiRequest({
|
|
3661
|
+
return Object.assign(Object.assign({}, baseInfo), { created_at: 0, method: (api === null || api === void 0 ? void 0 : api.method) ? (_a = api === null || api === void 0 ? void 0 : api.method) === null || _a === void 0 ? void 0 : _a.toUpperCase() : "GET", name: getSubstring(caseItem === null || caseItem === void 0 ? void 0 : caseItem.name, 255) || "New Test Case", parent_id: "0", protocol: "http/1.1", request: this.completionApiRequest({
|
|
3656
3662
|
header: (_c = (((_b = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _b === void 0 ? void 0 : _b.header) || [])) === null || _c === void 0 ? void 0 : _c.concat(((_d = api === null || api === void 0 ? void 0 : api.parameters) === null || _d === void 0 ? void 0 : _d.header) || []),
|
|
3657
3663
|
query: (_f = (((_e = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _e === void 0 ? void 0 : _e.query) || [])) === null || _f === void 0 ? void 0 : _f.concat(((_g = api === null || api === void 0 ? void 0 : api.parameters) === null || _g === void 0 ? void 0 : _g.query) || []),
|
|
3658
3664
|
cookie: (_j = (((_h = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _h === void 0 ? void 0 : _h.cookie) || [])) === null || _j === void 0 ? void 0 : _j.concat(((_k = api === null || api === void 0 ? void 0 : api.parameters) === null || _k === void 0 ? void 0 : _k.cookie) || []),
|
|
@@ -3880,12 +3886,25 @@ const completionPostmanTarget = (targetItem) => {
|
|
|
3880
3886
|
}
|
|
3881
3887
|
return [];
|
|
3882
3888
|
};
|
|
3883
|
-
|
|
3889
|
+
const getHostWithPortFromUrl = (urlString) => {
|
|
3890
|
+
try {
|
|
3891
|
+
const url = new URL(urlString);
|
|
3892
|
+
return url.host; // 返回包含端口号的host部分(如果有的话)
|
|
3893
|
+
}
|
|
3894
|
+
catch (error) {
|
|
3895
|
+
return '';
|
|
3896
|
+
}
|
|
3897
|
+
};
|
|
3898
|
+
const urlHost = getHostWithPortFromUrl((targetItem === null || targetItem === void 0 ? void 0 : targetItem.url) || '');
|
|
3899
|
+
const urlObj = {
|
|
3884
3900
|
raw: (targetItem === null || targetItem === void 0 ? void 0 : targetItem.url) || '',
|
|
3885
|
-
host: [(targetItem === null || targetItem === void 0 ? void 0 : targetItem.url) || ''],
|
|
3886
3901
|
query: getPostmanQuery((_b = (_a = targetItem === null || targetItem === void 0 ? void 0 : targetItem.request) === null || _a === void 0 ? void 0 : _a.query) === null || _b === void 0 ? void 0 : _b.parameter),
|
|
3887
3902
|
variable: getPostmanVariable((_d = (_c = targetItem === null || targetItem === void 0 ? void 0 : targetItem.request) === null || _c === void 0 ? void 0 : _c.restful) === null || _d === void 0 ? void 0 : _d.parameter)
|
|
3888
3903
|
};
|
|
3904
|
+
if (urlHost) {
|
|
3905
|
+
urlObj.host = [urlHost];
|
|
3906
|
+
}
|
|
3907
|
+
return urlObj;
|
|
3889
3908
|
};
|
|
3890
3909
|
const result = {
|
|
3891
3910
|
name: (targetItem === null || targetItem === void 0 ? void 0 : targetItem.name) || 'New HTTP',
|
|
@@ -3960,12 +3979,12 @@ const array2PostmanTree = (items, idName = 'id', pidName = 'pid') => {
|
|
|
3960
3979
|
};
|
|
3961
3980
|
}
|
|
3962
3981
|
if ((target === null || target === void 0 ? void 0 : target.target_type) == 'folder') {
|
|
3963
|
-
itemMap[id] = Object.assign(Object.assign({}, completionPostmanFolder(target)), {
|
|
3982
|
+
itemMap[id] = Object.assign(Object.assign({}, completionPostmanFolder(target)), { sort: target === null || target === void 0 ? void 0 : target.sort,
|
|
3964
3983
|
// name: target?.name || '',
|
|
3965
3984
|
item: itemMap[id]['item'] });
|
|
3966
3985
|
}
|
|
3967
3986
|
else {
|
|
3968
|
-
itemMap[id] = Object.assign({}, completionPostmanTarget(target));
|
|
3987
|
+
itemMap[id] = Object.assign(Object.assign({}, completionPostmanTarget(target)), { sort: target === null || target === void 0 ? void 0 : target.sort });
|
|
3969
3988
|
}
|
|
3970
3989
|
const treeItem = itemMap[id];
|
|
3971
3990
|
if (pid == 0 || pid == undefined) {
|
|
@@ -3978,8 +3997,10 @@ const array2PostmanTree = (items, idName = 'id', pidName = 'pid') => {
|
|
|
3978
3997
|
};
|
|
3979
3998
|
}
|
|
3980
3999
|
itemMap[pid].item.push(treeItem);
|
|
4000
|
+
itemMap[pid].item.sort((a, b) => (a === null || a === void 0 ? void 0 : a.sort) - b.sort);
|
|
3981
4001
|
}
|
|
3982
4002
|
}
|
|
4003
|
+
result.sort((a, b) => (a === null || a === void 0 ? void 0 : a.sort) - b.sort);
|
|
3983
4004
|
return result;
|
|
3984
4005
|
}
|
|
3985
4006
|
catch (error) {
|
|
@@ -3991,6 +4012,10 @@ const getPostmanAuth = (auth) => {
|
|
|
3991
4012
|
if (lodash.isPlainObject(auth)) {
|
|
3992
4013
|
const { type } = auth;
|
|
3993
4014
|
switch (type) {
|
|
4015
|
+
case 'noauth':
|
|
4016
|
+
return {
|
|
4017
|
+
type: 'noauth'
|
|
4018
|
+
};
|
|
3994
4019
|
case 'basic':
|
|
3995
4020
|
return {
|
|
3996
4021
|
type: "basic",
|
|
@@ -4920,7 +4945,7 @@ class HarToApipost {
|
|
|
4920
4945
|
project_id: this.project.project_id || "",
|
|
4921
4946
|
parent_id: "0",
|
|
4922
4947
|
target_type: "api",
|
|
4923
|
-
name: url || "New HTTP",
|
|
4948
|
+
name: getSubstring(url, 255) || "New HTTP",
|
|
4924
4949
|
version: 0,
|
|
4925
4950
|
sort: 0,
|
|
4926
4951
|
description: "",
|
|
@@ -5014,8 +5039,8 @@ class InsomniaToApipost {
|
|
|
5014
5039
|
}
|
|
5015
5040
|
initProject(resources, project_id) {
|
|
5016
5041
|
const projectInfo = resources === null || resources === void 0 ? void 0 : resources.find((e) => (e === null || e === void 0 ? void 0 : e._type) === "workspace");
|
|
5017
|
-
this.project.name = (projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.name) || "New Project";
|
|
5018
|
-
this.project.intro = (projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.description) || "";
|
|
5042
|
+
this.project.name = getSubstring(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.name, 64) || "New Project";
|
|
5043
|
+
this.project.intro = getSubstring(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.description, 1024) || "";
|
|
5019
5044
|
this.project.project_id = project_id;
|
|
5020
5045
|
}
|
|
5021
5046
|
completionParameter(parameter) {
|
|
@@ -5216,7 +5241,7 @@ class InsomniaToApipost {
|
|
|
5216
5241
|
parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
|
|
5217
5242
|
description: (item === null || item === void 0 ? void 0 : item.description) || '',
|
|
5218
5243
|
target_type: "websocket2",
|
|
5219
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New Websocket",
|
|
5244
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Websocket",
|
|
5220
5245
|
sort: 0,
|
|
5221
5246
|
version: 0,
|
|
5222
5247
|
mark_id: "1",
|
|
@@ -5273,7 +5298,7 @@ class InsomniaToApipost {
|
|
|
5273
5298
|
project_id: this.project.project_id || "",
|
|
5274
5299
|
parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
|
|
5275
5300
|
target_type: "graphql",
|
|
5276
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL",
|
|
5301
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL",
|
|
5277
5302
|
version: 0,
|
|
5278
5303
|
sort: 0,
|
|
5279
5304
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -5331,7 +5356,7 @@ class InsomniaToApipost {
|
|
|
5331
5356
|
project_id: this.project.project_id || "",
|
|
5332
5357
|
parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
|
|
5333
5358
|
target_type: "api",
|
|
5334
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP",
|
|
5359
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP",
|
|
5335
5360
|
version: 0,
|
|
5336
5361
|
sort: 0,
|
|
5337
5362
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -5407,7 +5432,7 @@ class InsomniaToApipost {
|
|
|
5407
5432
|
project_id: this.project.project_id || "",
|
|
5408
5433
|
parent_id: this.foldersMap[item === null || item === void 0 ? void 0 : item.parentId] || "0",
|
|
5409
5434
|
target_type: "folder",
|
|
5410
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
|
|
5435
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
|
|
5411
5436
|
version: 0,
|
|
5412
5437
|
sort: 0,
|
|
5413
5438
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -5724,6 +5749,7 @@ class PostmanToApipost {
|
|
|
5724
5749
|
return [];
|
|
5725
5750
|
}
|
|
5726
5751
|
completionApiRequestBody(body) {
|
|
5752
|
+
var _a, _b;
|
|
5727
5753
|
const params = {};
|
|
5728
5754
|
if (body) {
|
|
5729
5755
|
if ((body === null || body === void 0 ? void 0 : body.mode) === "formdata") {
|
|
@@ -5743,6 +5769,23 @@ class PostmanToApipost {
|
|
|
5743
5769
|
}
|
|
5744
5770
|
else if ((body === null || body === void 0 ? void 0 : body.mode) === "raw") {
|
|
5745
5771
|
params["mode"] = "json";
|
|
5772
|
+
switch ((_b = (_a = body === null || body === void 0 ? void 0 : body.options) === null || _a === void 0 ? void 0 : _a.raw) === null || _b === void 0 ? void 0 : _b.language) {
|
|
5773
|
+
case 'json':
|
|
5774
|
+
params["mode"] = "json";
|
|
5775
|
+
break;
|
|
5776
|
+
case 'xml':
|
|
5777
|
+
params["mode"] = "xml";
|
|
5778
|
+
break;
|
|
5779
|
+
case 'javascript':
|
|
5780
|
+
params["mode"] = "javascript";
|
|
5781
|
+
break;
|
|
5782
|
+
case 'text':
|
|
5783
|
+
params["mode"] = "plain";
|
|
5784
|
+
break;
|
|
5785
|
+
case 'html':
|
|
5786
|
+
params["mode"] = "html";
|
|
5787
|
+
break;
|
|
5788
|
+
}
|
|
5746
5789
|
params["raw"] = lodash.isString(body === null || body === void 0 ? void 0 : body.raw) ? getBeautifulRaw(body === null || body === void 0 ? void 0 : body.raw) : "";
|
|
5747
5790
|
}
|
|
5748
5791
|
}
|
|
@@ -5868,7 +5911,7 @@ class PostmanToApipost {
|
|
|
5868
5911
|
project_id: this.project.project_id || "",
|
|
5869
5912
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
5870
5913
|
target_type: "folder",
|
|
5871
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
|
|
5914
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
|
|
5872
5915
|
version: 0,
|
|
5873
5916
|
sort: 0,
|
|
5874
5917
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -5888,7 +5931,7 @@ class PostmanToApipost {
|
|
|
5888
5931
|
project_id: this.project.project_id || "",
|
|
5889
5932
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
5890
5933
|
target_type: "graphql",
|
|
5891
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL",
|
|
5934
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL",
|
|
5892
5935
|
version: 0,
|
|
5893
5936
|
sort: 0,
|
|
5894
5937
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -5947,7 +5990,7 @@ class PostmanToApipost {
|
|
|
5947
5990
|
project_id: this.project.project_id || "",
|
|
5948
5991
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
5949
5992
|
target_type: "api",
|
|
5950
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP",
|
|
5993
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP",
|
|
5951
5994
|
version: 0,
|
|
5952
5995
|
sort: 0,
|
|
5953
5996
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -6029,8 +6072,8 @@ class PostmanToApipost {
|
|
|
6029
6072
|
}
|
|
6030
6073
|
initProject(json, project_id) {
|
|
6031
6074
|
var _a, _b;
|
|
6032
|
-
this.project.name = ((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name) || "New Project";
|
|
6033
|
-
this.project.intro = ((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description) || "";
|
|
6075
|
+
this.project.name = getSubstring((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name, 64) || "New Project";
|
|
6076
|
+
this.project.intro = getSubstring((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description, 1024) || "";
|
|
6034
6077
|
this.project.project_id = project_id;
|
|
6035
6078
|
}
|
|
6036
6079
|
convert(json, project_id, option) {
|
|
@@ -6089,7 +6132,7 @@ class YapiToApipost {
|
|
|
6089
6132
|
project_id: this.project.project_id || "",
|
|
6090
6133
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
6091
6134
|
target_type: "folder",
|
|
6092
|
-
name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
|
|
6135
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
|
|
6093
6136
|
version: 0,
|
|
6094
6137
|
sort: 0,
|
|
6095
6138
|
description: (item === null || item === void 0 ? void 0 : item.description) || "",
|
|
@@ -6261,7 +6304,7 @@ class YapiToApipost {
|
|
|
6261
6304
|
project_id: this.project.project_id || "",
|
|
6262
6305
|
parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
|
|
6263
6306
|
target_type: "api",
|
|
6264
|
-
name: (item === null || item === void 0 ? void 0 : item.title) || "New HTTP",
|
|
6307
|
+
name: getSubstring(item === null || item === void 0 ? void 0 : item.title, 255) || "New HTTP",
|
|
6265
6308
|
version: 0,
|
|
6266
6309
|
sort: 0,
|
|
6267
6310
|
description: (item === null || item === void 0 ? void 0 : item.desc) || "",
|