echoapi-converter 0.0.32 → 0.0.34
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 +32 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,14 +4,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var lodash = require('lodash');
|
|
6
6
|
var ATools = require('apipost-tools');
|
|
7
|
+
var urlParse = require('url-parse');
|
|
7
8
|
var MockSchema = require('apipost-mock-schema');
|
|
8
9
|
var axios = require('axios');
|
|
9
10
|
var SwaggerClient = require('swagger-client');
|
|
10
|
-
require('url-parse');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
13
|
|
|
14
14
|
var ATools__default = /*#__PURE__*/_interopDefaultLegacy(ATools);
|
|
15
|
+
var urlParse__default = /*#__PURE__*/_interopDefaultLegacy(urlParse);
|
|
15
16
|
var MockSchema__default = /*#__PURE__*/_interopDefaultLegacy(MockSchema);
|
|
16
17
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
17
18
|
var SwaggerClient__default = /*#__PURE__*/_interopDefaultLegacy(SwaggerClient);
|
|
@@ -739,6 +740,31 @@ const completionMethod = (method) => {
|
|
|
739
740
|
}
|
|
740
741
|
return method;
|
|
741
742
|
};
|
|
743
|
+
// 根据query数组生成新的url
|
|
744
|
+
const genUrlByQuery = (url, parameter, query_add_equal = 1) => {
|
|
745
|
+
var _a;
|
|
746
|
+
let paramsStr = '';
|
|
747
|
+
let newUrl = url || '';
|
|
748
|
+
const handleEncode = (value = '') => {
|
|
749
|
+
let _value = lodash.cloneDeep(value);
|
|
750
|
+
try {
|
|
751
|
+
// 将#符号encode
|
|
752
|
+
_value = _value.replace(/#/g, encodeURIComponent('#'));
|
|
753
|
+
// 将&符号encode
|
|
754
|
+
_value = _value.replace(/&/g, encodeURIComponent('&'));
|
|
755
|
+
}
|
|
756
|
+
catch (e) { }
|
|
757
|
+
return _value;
|
|
758
|
+
};
|
|
759
|
+
lodash.forEach(parameter, (item) => {
|
|
760
|
+
if (item.key && lodash.isEqual(item.is_checked, 1)) {
|
|
761
|
+
paramsStr += `${paramsStr ? '&' : ''}${handleEncode(item.key)}${lodash.isEqual(query_add_equal, -1) && !item.value ? '' : '='}${handleEncode(item.value)}`;
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
// NOTE 原地址有hash的话,需拼接回去
|
|
765
|
+
newUrl = `${lodash.head(newUrl.split('?'))}${paramsStr ? '?' : ''}${paramsStr}${((_a = urlParse__default["default"](newUrl)) === null || _a === void 0 ? void 0 : _a.hash) || ''}`;
|
|
766
|
+
return newUrl;
|
|
767
|
+
};
|
|
742
768
|
|
|
743
769
|
// @ts-nocheck
|
|
744
770
|
class ApipostToSwagger {
|
|
@@ -4252,12 +4278,12 @@ class InsomniaToApipost {
|
|
|
4252
4278
|
request.auth["type"] = "basic";
|
|
4253
4279
|
request.auth["basic"] = {
|
|
4254
4280
|
username: (authentication === null || authentication === void 0 ? void 0 : authentication.username) || "",
|
|
4255
|
-
password: (authentication === null || authentication === void 0 ? void 0 : authentication.
|
|
4281
|
+
password: (authentication === null || authentication === void 0 ? void 0 : authentication.password) || "",
|
|
4256
4282
|
};
|
|
4257
4283
|
}
|
|
4258
4284
|
else if ((authentication === null || authentication === void 0 ? void 0 : authentication.type) === "digest") {
|
|
4259
4285
|
request.auth["type"] = "digest";
|
|
4260
|
-
request.auth["digest"] = Object.assign(Object.assign({}, request.auth.digest), { username: (authentication === null || authentication === void 0 ? void 0 : authentication.username) || "", password: (authentication === null || authentication === void 0 ? void 0 : authentication.
|
|
4286
|
+
request.auth["digest"] = Object.assign(Object.assign({}, request.auth.digest), { username: (authentication === null || authentication === void 0 ? void 0 : authentication.username) || "", password: (authentication === null || authentication === void 0 ? void 0 : authentication.password) || "" });
|
|
4261
4287
|
}
|
|
4262
4288
|
else if ((authentication === null || authentication === void 0 ? void 0 : authentication.type) === "oauth1") {
|
|
4263
4289
|
request.auth["type"] = "oauth1";
|
|
@@ -4271,7 +4297,7 @@ class InsomniaToApipost {
|
|
|
4271
4297
|
}
|
|
4272
4298
|
else if ((authentication === null || authentication === void 0 ? void 0 : authentication.type) === "ntlm") {
|
|
4273
4299
|
request.auth["type"] = "ntlm";
|
|
4274
|
-
request.auth["ntlm"] = Object.assign(Object.assign({}, request.auth.ntlm), { username: (authentication === null || authentication === void 0 ? void 0 : authentication.username) || "", password: (authentication === null || authentication === void 0 ? void 0 : authentication.
|
|
4300
|
+
request.auth["ntlm"] = Object.assign(Object.assign({}, request.auth.ntlm), { username: (authentication === null || authentication === void 0 ? void 0 : authentication.username) || "", password: (authentication === null || authentication === void 0 ? void 0 : authentication.password) || "" });
|
|
4275
4301
|
}
|
|
4276
4302
|
else if ((authentication === null || authentication === void 0 ? void 0 : authentication.type) === "iam") {
|
|
4277
4303
|
request.auth["type"] = "awsv4";
|
|
@@ -4538,7 +4564,7 @@ class InsomniaToApipost {
|
|
|
4538
4564
|
}
|
|
4539
4565
|
completionApis(resources) {
|
|
4540
4566
|
return resources === null || resources === void 0 ? void 0 : resources.reduce((pre, item) => {
|
|
4541
|
-
var _a;
|
|
4567
|
+
var _a, _b;
|
|
4542
4568
|
if ((item === null || item === void 0 ? void 0 : item._type) === "request_group" && lodash.has(this.foldersMap, item === null || item === void 0 ? void 0 : item._id)) {
|
|
4543
4569
|
pre.push({
|
|
4544
4570
|
target_id: this.foldersMap[item === null || item === void 0 ? void 0 : item._id] || ATools.snowflakeId(),
|
|
@@ -4563,6 +4589,7 @@ class InsomniaToApipost {
|
|
|
4563
4589
|
}
|
|
4564
4590
|
else {
|
|
4565
4591
|
const target = this.completionApiTarget(item);
|
|
4592
|
+
target.url = genUrlByQuery(lodash.cloneDeep(target.url), (_b = target.request.query) === null || _b === void 0 ? void 0 : _b.parameter);
|
|
4566
4593
|
pre.push(target);
|
|
4567
4594
|
}
|
|
4568
4595
|
}
|