echoapi-converter 0.0.33 → 0.0.35

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.
Files changed (2) hide show
  1. package/dist/index.js +45 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var lodash = require('lodash');
6
6
  var ATools = require('apipost-tools');
7
- require('url-parse');
7
+ var urlParse = require('url-parse');
8
8
  var MockSchema = require('apipost-mock-schema');
9
9
  var axios = require('axios');
10
10
  var SwaggerClient = require('swagger-client');
@@ -12,6 +12,7 @@ var SwaggerClient = require('swagger-client');
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 {
@@ -3596,6 +3622,12 @@ class ApifoxToApipost {
3596
3622
  name: 'New Query',
3597
3623
  query: lodash.isString((_a = requestBody === null || requestBody === void 0 ? void 0 : requestBody.graphql) === null || _a === void 0 ? void 0 : _a.query) ? (_b = requestBody === null || requestBody === void 0 ? void 0 : requestBody.graphql) === null || _b === void 0 ? void 0 : _b.query : '',
3598
3624
  variables: lodash.isString((_c = requestBody === null || requestBody === void 0 ? void 0 : requestBody.graphql) === null || _c === void 0 ? void 0 : _c.variables) ? (_d = requestBody === null || requestBody === void 0 ? void 0 : requestBody.graphql) === null || _d === void 0 ? void 0 : _d.variables : '',
3625
+ response: {
3626
+ mode: 'json',
3627
+ raw: '',
3628
+ raw_parameter: [],
3629
+ raw_schema: { type: 'object' },
3630
+ },
3599
3631
  }],
3600
3632
  };
3601
3633
  }
@@ -4399,7 +4431,12 @@ class InsomniaToApipost {
4399
4431
  completionGraphqlRequestBody(body) {
4400
4432
  return {
4401
4433
  query_schema: {},
4402
- query_list: [Object.assign({ param_id: ATools.snowflakeId(), name: 'New Query' }, this.getGraphQLQuery(body === null || body === void 0 ? void 0 : body.text))],
4434
+ query_list: [Object.assign(Object.assign({ param_id: ATools.snowflakeId(), name: 'New Query' }, this.getGraphQLQuery(body === null || body === void 0 ? void 0 : body.text)), { response: {
4435
+ mode: 'json',
4436
+ raw: '',
4437
+ raw_parameter: [],
4438
+ raw_schema: { type: 'object' },
4439
+ } })],
4403
4440
  };
4404
4441
  }
4405
4442
  completionGraphqlTarget(item) {
@@ -4917,6 +4954,12 @@ class PostmanToApipost {
4917
4954
  name: 'New Query',
4918
4955
  query: lodash.isString((_k = (_j = request === null || request === void 0 ? void 0 : request.body) === null || _j === void 0 ? void 0 : _j.graphql) === null || _k === void 0 ? void 0 : _k.query) ? (_m = (_l = request === null || request === void 0 ? void 0 : request.body) === null || _l === void 0 ? void 0 : _l.graphql) === null || _m === void 0 ? void 0 : _m.query : '',
4919
4956
  variables: lodash.isString((_p = (_o = request === null || request === void 0 ? void 0 : request.body) === null || _o === void 0 ? void 0 : _o.graphql) === null || _p === void 0 ? void 0 : _p.variables) ? (_r = (_q = request === null || request === void 0 ? void 0 : request.body) === null || _q === void 0 ? void 0 : _q.graphql) === null || _r === void 0 ? void 0 : _r.variables : '',
4957
+ response: {
4958
+ mode: 'json',
4959
+ raw: '',
4960
+ raw_parameter: [],
4961
+ raw_schema: { type: 'object' },
4962
+ },
4920
4963
  }],
4921
4964
  },
4922
4965
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [