echoapi-converter 0.0.87 → 0.0.88

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.d.ts CHANGED
@@ -205,6 +205,7 @@ declare class PostmanToApipost {
205
205
  apis: any;
206
206
  project: any;
207
207
  source: 'vscode' | 'workbench' | string;
208
+ file_parsing_rules: 'normal' | 'use_case' | string;
208
209
  constructor();
209
210
  private clear;
210
211
  private completionApiRequestAuth;
@@ -214,12 +215,14 @@ declare class PostmanToApipost {
214
215
  private completionApiRequest;
215
216
  private completionApiResponse;
216
217
  private completionApiFolder;
218
+ private completionApiCase;
217
219
  private completionApiTarget;
218
220
  private completionApis;
219
221
  private initApis;
220
222
  private initProject;
221
223
  convert(json: any, project_id: string, option?: {
222
- source: string;
224
+ source?: string;
225
+ file_parsing_rules?: string;
223
226
  }): {
224
227
  status: "error" | "success";
225
228
  message: string;
package/dist/index.js CHANGED
@@ -6945,6 +6945,13 @@ class PostmanToApipost {
6945
6945
  writable: true,
6946
6946
  value: void 0
6947
6947
  });
6948
+ // 文件解析规则
6949
+ Object.defineProperty(this, "file_parsing_rules", {
6950
+ enumerable: true,
6951
+ configurable: true,
6952
+ writable: true,
6953
+ value: void 0
6954
+ });
6948
6955
  this.apis = [];
6949
6956
  this.project = {
6950
6957
  name: "",
@@ -7470,6 +7477,24 @@ class PostmanToApipost {
7470
7477
  is_socket: 1,
7471
7478
  };
7472
7479
  }
7480
+ completionApiCase(item, caseTarget) {
7481
+ const sample_id = apipostTools.snowflakeId();
7482
+ return {
7483
+ sample_id: sample_id,
7484
+ parent_id: item === null || item === void 0 ? void 0 : item.target_id,
7485
+ target_id: sample_id,
7486
+ project_id: this.project.project_id || "",
7487
+ name: caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.name,
7488
+ type: 'sample',
7489
+ target_type: "sample",
7490
+ method: caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.method,
7491
+ url: caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.url,
7492
+ sort: 0,
7493
+ description: caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.description,
7494
+ protocol: (caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.protocol) || "http/1.1",
7495
+ request: caseTarget === null || caseTarget === void 0 ? void 0 : caseTarget.request,
7496
+ };
7497
+ }
7473
7498
  completionApiTarget(item, parentInfo) {
7474
7499
  var _a, _b, _c;
7475
7500
  const { request, response } = item || {};
@@ -7522,19 +7547,30 @@ class PostmanToApipost {
7522
7547
  is_force: -1,
7523
7548
  };
7524
7549
  }
7525
- completionApis(item, parentInfo) {
7550
+ completionApis(item, parentInfo, targetObj) {
7526
7551
  if (item === null || item === void 0 ? void 0 : item.length) {
7527
7552
  return item === null || item === void 0 ? void 0 : item.reduce((pre, targetItem) => {
7528
7553
  if (!lodash.has(targetItem, "item")) {
7529
7554
  // 接口
7530
- const target = this.completionApiTarget(targetItem, parentInfo);
7555
+ let target = this.completionApiTarget(targetItem, parentInfo);
7556
+ // 文件解析规则为同接口转用例 记录同mtehod和同url的接口
7557
+ if (this.file_parsing_rules === 'use_case' && target.target_type === 'api') {
7558
+ if (lodash.has(targetObj, `${target.method}:${target.url}`)) {
7559
+ // 有重复改为用例 并把parent_id 改掉
7560
+ target = this.completionApiCase(targetObj[`${target.method}:${target.url}`], target);
7561
+ // console.log(target,"case-target");
7562
+ }
7563
+ else {
7564
+ targetObj[`${target.method}:${target.url}`] = target;
7565
+ }
7566
+ }
7531
7567
  pre.push(target);
7532
7568
  }
7533
7569
  else {
7534
7570
  // 目录
7535
7571
  const parent = this.completionApiFolder(targetItem, parentInfo);
7536
7572
  pre.push(parent);
7537
- pre = pre.concat(this.completionApis(targetItem === null || targetItem === void 0 ? void 0 : targetItem.item, parent));
7573
+ pre = pre.concat(this.completionApis(targetItem === null || targetItem === void 0 ? void 0 : targetItem.item, parent, targetObj));
7538
7574
  }
7539
7575
  return pre;
7540
7576
  }, []);
@@ -7543,7 +7579,8 @@ class PostmanToApipost {
7543
7579
  }
7544
7580
  initApis(item) {
7545
7581
  if (isArray(item)) {
7546
- this.apis = this.completionApis(item);
7582
+ const targetObj = {};
7583
+ this.apis = this.completionApis(item, null, targetObj);
7547
7584
  }
7548
7585
  }
7549
7586
  initProject(json, project_id) {
@@ -7556,6 +7593,7 @@ class PostmanToApipost {
7556
7593
  this.clear();
7557
7594
  try {
7558
7595
  this.source = (option === null || option === void 0 ? void 0 : option.source) || 'workbench';
7596
+ this.file_parsing_rules = (option === null || option === void 0 ? void 0 : option.file_parsing_rules) || 'normal';
7559
7597
  this.initProject(json, project_id);
7560
7598
  this.initApis(json === null || json === void 0 ? void 0 : json.item);
7561
7599
  const data = Object.assign(Object.assign({}, this.project), { apis: this.apis });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.87",
3
+ "version": "0.0.88",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [