echoapi-converter 0.0.48 → 0.0.50

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 +46 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -616,11 +616,10 @@ const handleSocketMethodRequestBody = (body, pathItem) => {
616
616
  };
617
617
  }
618
618
  else {
619
- let modeStr = MODE_TYPE[mode];
620
- if (modeStr) {
621
- pathItem.requestBody.content[modeStr] = {
622
- 'x-mode': modeStr || '',
623
- schema: {
619
+ if (mode) {
620
+ pathItem.requestBody.content[mode] = {
621
+ 'x-mode': mode || '',
622
+ schema: lodash.isPlainObject(body === null || body === void 0 ? void 0 : body.raw_schema) && !lodash.isEmpty(body === null || body === void 0 ? void 0 : body.raw_schema) ? body === null || body === void 0 ? void 0 : body.raw_schema : {
624
623
  type: "object",
625
624
  },
626
625
  example: (body === null || body === void 0 ? void 0 : body.raw) || "",
@@ -730,7 +729,7 @@ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
730
729
  }
731
730
  };
732
731
  const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, target_type) => {
733
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
732
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15;
734
733
  const path = recursiveFolderPath("", sourceObj, pid, pidName);
735
734
  const pathItem = {
736
735
  'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || '',
@@ -746,7 +745,7 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
746
745
  pathItem['x-mark-id'] = item === null || item === void 0 ? void 0 : item.mark_id;
747
746
  }
748
747
  if (lodash.isString(item === null || item === void 0 ? void 0 : item.updated_at)) {
749
- pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.tags;
748
+ pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.updated_at;
750
749
  }
751
750
  if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
752
751
  pathItem['x-updated-user-name'] = (_b = item === null || item === void 0 ? void 0 : item.updated_user) === null || _b === void 0 ? void 0 : _b.nick_name;
@@ -762,12 +761,13 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
762
761
  handlePathItemParameters("query", ((_d = (_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.parameter) || [], pathItem);
763
762
  handlePathItemParameters("header", ((_f = (_e = item === null || item === void 0 ? void 0 : item.request) === null || _e === void 0 ? void 0 : _e.header) === null || _f === void 0 ? void 0 : _f.parameter) || [], pathItem);
764
763
  handlePathItemParameters("cookie", ((_h = (_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.cookie) === null || _h === void 0 ? void 0 : _h.parameter) || [], pathItem);
764
+ handlePathItemParameters("path", ((_k = (_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.restful) === null || _k === void 0 ? void 0 : _k.parameter) || [], pathItem);
765
765
  // 处理请求体参数(根据 Swagger 版本)
766
766
  if (apiVersion === "2.0") {
767
- handlePathItemBodyParameters(((_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.body) || {}, pathItem, modelsObj);
767
+ handlePathItemBodyParameters(((_l = item === null || item === void 0 ? void 0 : item.request) === null || _l === void 0 ? void 0 : _l.body) || {}, pathItem, modelsObj);
768
768
  }
769
769
  else {
770
- handlePathItemRequestBody(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
770
+ handlePathItemRequestBody(((_m = item === null || item === void 0 ? void 0 : item.request) === null || _m === void 0 ? void 0 : _m.body) || {}, pathItem, modelsObj);
771
771
  }
772
772
  // 添加路径标签
773
773
  if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
@@ -782,22 +782,23 @@ const createPathItem = (item, sourceObj, pid, pidName, modelsObj, apiVersion, ta
782
782
  switch (target_type) {
783
783
  case 'socketio':
784
784
  pathItem.description = `${pathItem.description}
785
- Over a secure connection,${((_l = item === null || item === void 0 ? void 0 : item.config) === null || _l === void 0 ? void 0 : _l.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},And use the client version ${((_m = item === null || item === void 0 ? void 0 : item.config) === null || _m === void 0 ? void 0 : _m.socket_version) || 'v4'}And the specified handshake path ${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.shake_hands_path) || '/socket.io'} make a connection.`;
785
+ Over a secure connection,${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},And use the client version ${((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.socket_version) || 'v4'}And the specified handshake path ${((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.shake_hands_path) || '/socket.io'} make a connection.`;
786
786
  break;
787
787
  case 'websocket2':
788
788
  pathItem.description = `${pathItem.description}
789
- Over a secure connection,${((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},${((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.information_size) == 0 ? 'And there is no limit to the maximum sent content that can be received。' : `And the maximum sent content allowed to be received is${((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.information_size) || 5}M。`}`;
789
+ Over a secure connection,${((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},${((_s = item === null || item === void 0 ? void 0 : item.config) === null || _s === void 0 ? void 0 : _s.information_size) == 0 ? 'And there is no limit to the maximum sent content that can be received。' : `And the maximum sent content allowed to be received is${((_t = item === null || item === void 0 ? void 0 : item.config) === null || _t === void 0 ? void 0 : _t.information_size) || 5}M。`}`;
790
790
  break;
791
791
  }
792
792
  }
793
- handlePathItemParameters("query", ((_t = (_s = item === null || item === void 0 ? void 0 : item.request) === null || _s === void 0 ? void 0 : _s.query) === null || _t === void 0 ? void 0 : _t.parameter) || [], pathItem);
794
- handlePathItemParameters("header", ((_v = (_u = item === null || item === void 0 ? void 0 : item.request) === null || _u === void 0 ? void 0 : _u.header) === null || _v === void 0 ? void 0 : _v.parameter) || [], pathItem);
795
- handlePathItemParameters("cookie", ((_x = (_w = item === null || item === void 0 ? void 0 : item.request) === null || _w === void 0 ? void 0 : _w.cookie) === null || _x === void 0 ? void 0 : _x.parameter) || [], pathItem);
793
+ handlePathItemParameters("query", ((_v = (_u = item === null || item === void 0 ? void 0 : item.request) === null || _u === void 0 ? void 0 : _u.query) === null || _v === void 0 ? void 0 : _v.parameter) || [], pathItem);
794
+ handlePathItemParameters("header", ((_x = (_w = item === null || item === void 0 ? void 0 : item.request) === null || _w === void 0 ? void 0 : _w.header) === null || _x === void 0 ? void 0 : _x.parameter) || [], pathItem);
795
+ handlePathItemParameters("cookie", ((_z = (_y = item === null || item === void 0 ? void 0 : item.request) === null || _y === void 0 ? void 0 : _y.cookie) === null || _z === void 0 ? void 0 : _z.parameter) || [], pathItem);
796
+ handlePathItemParameters("path", ((_1 = (_0 = item === null || item === void 0 ? void 0 : item.request) === null || _0 === void 0 ? void 0 : _0.restful) === null || _1 === void 0 ? void 0 : _1.parameter) || [], pathItem);
796
797
  if (target_type == 'socketio')
797
- handlePathItemParameters("event", ((_z = (_y = item === null || item === void 0 ? void 0 : item.request) === null || _y === void 0 ? void 0 : _y.event) === null || _z === void 0 ? void 0 : _z.parameter) || [], pathItem);
798
+ handlePathItemParameters("event", ((_3 = (_2 = item === null || item === void 0 ? void 0 : item.request) === null || _2 === void 0 ? void 0 : _2.event) === null || _3 === void 0 ? void 0 : _3.parameter) || [], pathItem);
798
799
  // 处理请体
799
800
  if (target_type == 'graphql') {
800
- handleGraphqlRequestBody(((_1 = (_0 = item === null || item === void 0 ? void 0 : item.request) === null || _0 === void 0 ? void 0 : _0.body) === null || _1 === void 0 ? void 0 : _1.query_list) || [], ((_3 = (_2 = item === null || item === void 0 ? void 0 : item.request) === null || _2 === void 0 ? void 0 : _2.body) === null || _3 === void 0 ? void 0 : _3.query_schema) || {}, pathItem, modelsObj);
801
+ handleGraphqlRequestBody(((_5 = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.body) === null || _5 === void 0 ? void 0 : _5.query_list) || [], ((_7 = (_6 = item === null || item === void 0 ? void 0 : item.request) === null || _6 === void 0 ? void 0 : _6.body) === null || _7 === void 0 ? void 0 : _7.query_schema) || {}, pathItem, modelsObj);
801
802
  }
802
803
  else {
803
804
  handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
@@ -809,10 +810,10 @@ Over a secure connection,${((_p = item === null || item === void 0 ? void 0 :
809
810
  }
810
811
  else if (target_type == 'socket_method') {
811
812
  // 拼接description
812
- const configs = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.configs;
813
+ const configs = (_8 = item === null || item === void 0 ? void 0 : item.request) === null || _8 === void 0 ? void 0 : _8.configs;
813
814
  if (lodash.isPlainObject(configs)) {
814
- let requestString = `The encoding format of the request packet is ${configs === null || configs === void 0 ? void 0 : configs.charset} ${lodash.isArray((_5 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _5 === void 0 ? void 0 : _5.request) && ((_6 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _6 === void 0 ? void 0 : _6.request.length) > 0 ?
815
- (_7 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _7 === void 0 ? void 0 : _7.request.map((r, index) => {
815
+ let requestString = `The encoding format of the request packet is ${configs === null || configs === void 0 ? void 0 : configs.charset} ${lodash.isArray((_9 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _9 === void 0 ? void 0 : _9.request) && ((_10 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _10 === void 0 ? void 0 : _10.request.length) > 0 ?
816
+ (_11 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _11 === void 0 ? void 0 : _11.request.map((r, index) => {
816
817
  var _a;
817
818
  let str = getTcpMethodFucString(r);
818
819
  if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
@@ -820,7 +821,7 @@ Over a secure connection,${((_p = item === null || item === void 0 ? void 0 :
820
821
  }
821
822
  return str;
822
823
  }) : ''}`;
823
- let responseString = lodash.isArray((_8 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _8 === void 0 ? void 0 : _8.response) && ((_9 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _9 === void 0 ? void 0 : _9.response.length) > 0 ? (_10 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _10 === void 0 ? void 0 : _10.response.map((r, index) => {
824
+ let responseString = lodash.isArray((_12 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _12 === void 0 ? void 0 : _12.response) && ((_13 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _13 === void 0 ? void 0 : _13.response.length) > 0 ? (_14 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _14 === void 0 ? void 0 : _14.response.map((r, index) => {
824
825
  var _a;
825
826
  let str = getTcpMethodFucString(r);
826
827
  if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
@@ -830,7 +831,7 @@ Over a secure connection,${((_p = item === null || item === void 0 ? void 0 :
830
831
  }) : '';
831
832
  pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
832
833
  }
833
- handleSocketMethodRequestBody(((_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.body) || {}, pathItem);
834
+ handleSocketMethodRequestBody(((_15 = item === null || item === void 0 ? void 0 : item.request) === null || _15 === void 0 ? void 0 : _15.body) || {}, pathItem);
834
835
  // 处理响应
835
836
  pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
836
837
  // 添加路径标签
@@ -1327,7 +1328,12 @@ class ApipostToSwagger {
1327
1328
  paths[temp_url][targetMethod] = pathItem;
1328
1329
  }
1329
1330
  else if (pathItem.tags.length > 0) {
1330
- paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1331
+ lodash.forEach(pathItem.tags, tag => {
1332
+ if (!paths[temp_url][targetMethod].tags.includes(tag)) {
1333
+ // 排除重复目录
1334
+ paths[temp_url][targetMethod].tags.push(tag);
1335
+ }
1336
+ });
1331
1337
  }
1332
1338
  }
1333
1339
  else if (["folder", "socket"].includes(item.target_type)) {
@@ -1365,7 +1371,12 @@ ${item.description}
1365
1371
  paths[temp_url][targetMethod] = pathItem;
1366
1372
  }
1367
1373
  else if (pathItem.tags.length > 0) {
1368
- paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1374
+ lodash.forEach(pathItem.tags, tag => {
1375
+ if (!paths[temp_url][targetMethod].tags.includes(tag)) {
1376
+ // 排除重复目录
1377
+ paths[temp_url][targetMethod].tags.push(tag);
1378
+ }
1379
+ });
1369
1380
  }
1370
1381
  }
1371
1382
  else if (item.target_type === 'socket_method') {
@@ -1378,7 +1389,12 @@ ${item.description}
1378
1389
  paths[temp_url][targetMethod] = pathItem;
1379
1390
  }
1380
1391
  else if (pathItem.tags.length > 0) {
1381
- paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1392
+ lodash.forEach(pathItem.tags, tag => {
1393
+ if (!paths[temp_url][targetMethod].tags.includes(tag)) {
1394
+ // 排除重复目录
1395
+ paths[temp_url][targetMethod].tags.push(tag);
1396
+ }
1397
+ });
1382
1398
  }
1383
1399
  }
1384
1400
  else if (item.target_type === 'doc') {
@@ -1391,7 +1407,12 @@ ${item.description}
1391
1407
  paths[temp_url][targetMethod] = pathItem;
1392
1408
  }
1393
1409
  else if (pathItem.tags.length > 0) {
1394
- paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1410
+ lodash.forEach(pathItem.tags, tag => {
1411
+ if (!paths[temp_url][targetMethod].tags.includes(tag)) {
1412
+ // 排除重复目录
1413
+ paths[temp_url][targetMethod].tags.push(tag);
1414
+ }
1415
+ });
1395
1416
  }
1396
1417
  }
1397
1418
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.48",
3
+ "version": "0.0.50",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [