echoapi-converter 0.0.63 → 0.0.64

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
@@ -212,6 +212,7 @@ declare class PostmanToApipost {
212
212
  private completionApiRequestBody;
213
213
  private completionGraphqlRequest;
214
214
  private completionApiRequest;
215
+ private completionApiResponse;
215
216
  private completionApiFolder;
216
217
  private completionApiTarget;
217
218
  private completionApis;
package/dist/index.js CHANGED
@@ -10,6 +10,7 @@ var MockSchema = require('apipost-mock-schema');
10
10
  var axios = require('axios');
11
11
  var SwaggerClient = require('swagger-client');
12
12
  var toJsonSchemasecond = require('to-json-schema');
13
+ var JSON5 = require('json5');
13
14
 
14
15
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
16
 
@@ -19,6 +20,7 @@ var MockSchema__default = /*#__PURE__*/_interopDefaultLegacy(MockSchema);
19
20
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
20
21
  var SwaggerClient__default = /*#__PURE__*/_interopDefaultLegacy(SwaggerClient);
21
22
  var toJsonSchemasecond__default = /*#__PURE__*/_interopDefaultLegacy(toJsonSchemasecond);
23
+ var JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5);
22
24
 
23
25
  /******************************************************************************
24
26
  Copyright (c) Microsoft Corporation.
@@ -75,7 +77,7 @@ const MODE_TYPE = {
75
77
  html: "text/html",
76
78
  };
77
79
  const DEFAULT_AUTH = {
78
- type: "noauth",
80
+ type: "inherit",
79
81
  kv: { key: "", value: "", in: "header" },
80
82
  bearer: { key: "" },
81
83
  basic: { username: "", password: "" },
@@ -901,9 +903,7 @@ const handlePathItemParameters = (type, arr, pathItem) => {
901
903
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
902
904
  required: (item === null || item === void 0 ? void 0 : item.not_null) === 1,
903
905
  example: String((item === null || item === void 0 ? void 0 : item.value) || ""),
904
- schema: {
905
- type: (_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase(),
906
- },
906
+ schema: Object.assign({ type: (_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase() }, ((item === null || item === void 0 ? void 0 : item.schema) || {})),
907
907
  });
908
908
  }
909
909
  }
@@ -1317,6 +1317,9 @@ const transExample = (example) => {
1317
1317
  const getBeautifulRaw = (raw) => {
1318
1318
  var _a;
1319
1319
  try {
1320
+ if (!raw) {
1321
+ return raw;
1322
+ }
1320
1323
  return (_a = apipostTools.beautifyRaw(raw)) === null || _a === void 0 ? void 0 : _a.value;
1321
1324
  }
1322
1325
  catch (err) {
@@ -1386,7 +1389,7 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1386
1389
  url = `http://${url}`;
1387
1390
  }
1388
1391
  const urlObj = createUrl(url);
1389
- const paths = urlObj.pathname.split("/");
1392
+ const paths = urlObj.pathname.split('/');
1390
1393
  lodash.forEach(paths, (pathsItem) => {
1391
1394
  if (pathsItem.substring(0, 1) === ":" && pathsItem.length > 1) {
1392
1395
  let obj = null;
@@ -1398,12 +1401,13 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1398
1401
  }
1399
1402
  restfulList.push({
1400
1403
  param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
1401
- field_type: "String",
1404
+ field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
1402
1405
  is_checked: 1,
1403
1406
  key: pathsItem.substring(1, pathsItem.length),
1404
1407
  not_null: 1,
1405
- value: (obj === null || obj === void 0 ? void 0 : obj.value) || "",
1406
- description: (obj === null || obj === void 0 ? void 0 : obj.description) || "",
1408
+ value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
1409
+ description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
1410
+ schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
1407
1411
  });
1408
1412
  }
1409
1413
  });
@@ -1423,12 +1427,13 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1423
1427
  }
1424
1428
  restfulList.push({
1425
1429
  param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
1426
- field_type: "String",
1430
+ field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
1427
1431
  is_checked: 1,
1428
1432
  key: matchesItem,
1429
1433
  not_null: 1,
1430
- value: (obj === null || obj === void 0 ? void 0 : obj.value) || "",
1431
- description: (obj === null || obj === void 0 ? void 0 : obj.description) || "",
1434
+ value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
1435
+ description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
1436
+ schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
1432
1437
  });
1433
1438
  }
1434
1439
  });
@@ -2035,7 +2040,7 @@ const replaceRef = (schemaObj) => {
2035
2040
  // 如果当前属性的值是一个对象,则递归遍历该对象
2036
2041
  if (typeof value === 'object' && value !== null) {
2037
2042
  // 查找并替换 insAppInfo 对象
2038
- if (lodash.has(value, 'ref') || lodash.has(value, '$$ref')) {
2043
+ if (lodash.has(value, 'ref') || lodash.has(value, '$ref')) {
2039
2044
  let newIuid = apipostTools.snowflakeId();
2040
2045
  if ((value === null || value === void 0 ? void 0 : value.ref) && value.ref.startsWith('http://localhost:8000/')) {
2041
2046
  const index = (_a = value.ref) === null || _a === void 0 ? void 0 : _a.indexOf('#');
@@ -2046,7 +2051,7 @@ const replaceRef = (schemaObj) => {
2046
2051
  schemaObj[key] = {
2047
2052
  ['x-schema-refs']: {
2048
2053
  [newIuid]: {
2049
- ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$$ref'])
2054
+ ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
2050
2055
  },
2051
2056
  },
2052
2057
  properties: {},
@@ -2077,7 +2082,7 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
2077
2082
  jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-overrides\"/g, '\"x-schema-overrides\"');
2078
2083
  // 还原为对象
2079
2084
  jsonSchema = JSON.parse(jsonSchemaStr);
2080
- if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$$ref')) {
2085
+ if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$ref')) {
2081
2086
  let newIuid = apipostTools.snowflakeId();
2082
2087
  if ((jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) && jsonSchema.ref.startsWith("http://localhost:8000/")) {
2083
2088
  // jsonSchema.ref = jsonSchema.ref.substring(22);
@@ -2089,7 +2094,7 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
2089
2094
  jsonSchema = {
2090
2095
  ['x-schema-refs']: {
2091
2096
  [newIuid]: {
2092
- $ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$$ref'])
2097
+ $ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$ref'])
2093
2098
  },
2094
2099
  },
2095
2100
  properties: {},
@@ -2137,8 +2142,8 @@ const createNewModelData = (item, key, folder_name) => {
2137
2142
  var model = {
2138
2143
  model_id: `#/components/${folder_name}/${key}`,
2139
2144
  name: key || (item === null || item === void 0 ? void 0 : item.title) || key || 'New Schema',
2140
- displayName: key || (item === null || item === void 0 ? void 0 : item.title) || '',
2141
- display_name: key || (item === null || item === void 0 ? void 0 : item.title) || '',
2145
+ // displayName:key || item?.title || '',
2146
+ // display_name:key || item?.title || '',
2142
2147
  model_type: 'model',
2143
2148
  description: (item === null || item === void 0 ? void 0 : item.description) || '',
2144
2149
  schema: {},
@@ -2166,6 +2171,17 @@ const getFidldType = (type) => {
2166
2171
  }
2167
2172
  return 'String';
2168
2173
  };
2174
+ const getExampleId = (status) => {
2175
+ if (status == 200) {
2176
+ return '1';
2177
+ }
2178
+ else if (status == 404) {
2179
+ return '2';
2180
+ }
2181
+ else {
2182
+ return apipostTools.snowflakeId();
2183
+ }
2184
+ };
2169
2185
 
2170
2186
  class SwaggerToApipost {
2171
2187
  constructor() {
@@ -2256,6 +2272,9 @@ class SwaggerToApipost {
2256
2272
  getBeautifulRaw(raw) {
2257
2273
  var _a;
2258
2274
  try {
2275
+ if (!raw) {
2276
+ return raw;
2277
+ }
2259
2278
  return (_a = apipostTools.beautifyRaw(raw)) === null || _a === void 0 ? void 0 : _a.value;
2260
2279
  }
2261
2280
  catch (err) {
@@ -2434,6 +2453,7 @@ class SwaggerToApipost {
2434
2453
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2435
2454
  field_type: getFidldType((_b = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _b === void 0 ? void 0 : _b.type), // 类型
2436
2455
  param_id: apipostTools.snowflakeId(),
2456
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2437
2457
  });
2438
2458
  }
2439
2459
  else if (parameter.in == "header") {
@@ -2454,6 +2474,7 @@ class SwaggerToApipost {
2454
2474
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2455
2475
  field_type: getFidldType((_d = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _d === void 0 ? void 0 : _d.type), // 类型
2456
2476
  param_id: apipostTools.snowflakeId(),
2477
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2457
2478
  });
2458
2479
  }
2459
2480
  else if (parameter.in == "path") {
@@ -2474,6 +2495,7 @@ class SwaggerToApipost {
2474
2495
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2475
2496
  field_type: getFidldType((_f = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _f === void 0 ? void 0 : _f.type), // 类型
2476
2497
  param_id: apipostTools.snowflakeId(),
2498
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2477
2499
  });
2478
2500
  }
2479
2501
  }
@@ -2518,6 +2540,7 @@ class SwaggerToApipost {
2518
2540
  ? item.type.charAt(0).toUpperCase() + item.type.slice(1)
2519
2541
  : "String",
2520
2542
  param_id: apipostTools.snowflakeId(),
2543
+ schema: (item === null || item === void 0 ? void 0 : item.schema) || {}
2521
2544
  });
2522
2545
  }
2523
2546
  }
@@ -2586,7 +2609,7 @@ class SwaggerToApipost {
2586
2609
  jsonSchema = element.schema;
2587
2610
  }
2588
2611
  // 成功响应示例
2589
- if (status == 200) {
2612
+ if (String(status) == '200') {
2590
2613
  response.example.push({
2591
2614
  example_id: "1",
2592
2615
  raw: Raw_text,
@@ -2602,7 +2625,7 @@ class SwaggerToApipost {
2602
2625
  },
2603
2626
  });
2604
2627
  }
2605
- else if (status == 404) {
2628
+ else if (String(status) == '404') {
2606
2629
  response.example.push({
2607
2630
  example_id: "2",
2608
2631
  raw: Raw_text,
@@ -2770,7 +2793,7 @@ class SwaggerToApipost {
2770
2793
  }
2771
2794
  else {
2772
2795
  response.example.push({
2773
- example_id: apipostTools.snowflakeId(),
2796
+ example_id: getExampleId(status),
2774
2797
  raw: "",
2775
2798
  raw_parameter: [],
2776
2799
  expect: {
@@ -2906,7 +2929,7 @@ class SwaggerToApipost {
2906
2929
  not_null: 1,
2907
2930
  description: "",
2908
2931
  field_type: "String",
2909
- param_id: apipostTools.snowflakeId(),
2932
+ param_id: apipostTools.snowflakeId()
2910
2933
  });
2911
2934
  }
2912
2935
  if (lodash.has(swaggerApi, "parameters")) {
@@ -2941,6 +2964,7 @@ class SwaggerToApipost {
2941
2964
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2942
2965
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2943
2966
  param_id: apipostTools.snowflakeId(),
2967
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2944
2968
  });
2945
2969
  }
2946
2970
  else if (parameter.in == "header") {
@@ -2961,6 +2985,7 @@ class SwaggerToApipost {
2961
2985
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2962
2986
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2963
2987
  param_id: apipostTools.snowflakeId(),
2988
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2964
2989
  });
2965
2990
  }
2966
2991
  else if (parameter.in == "path") {
@@ -2981,6 +3006,7 @@ class SwaggerToApipost {
2981
3006
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2982
3007
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2983
3008
  param_id: apipostTools.snowflakeId(),
3009
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2984
3010
  });
2985
3011
  }
2986
3012
  else if (parameter.in == "body") {
@@ -3030,6 +3056,7 @@ class SwaggerToApipost {
3030
3056
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
3031
3057
  field_type: getFidldType(((_g = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _g === void 0 ? void 0 : _g.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type)), // 类型
3032
3058
  param_id: apipostTools.snowflakeId(),
3059
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
3033
3060
  });
3034
3061
  }
3035
3062
  }
@@ -3066,7 +3093,7 @@ class SwaggerToApipost {
3066
3093
  jsonSchema = element.schema;
3067
3094
  }
3068
3095
  // 成功响应示例
3069
- if (status == 200) {
3096
+ if (String(status) == '200') {
3070
3097
  response.example.push({
3071
3098
  example_id: "1",
3072
3099
  raw: Raw_text,
@@ -3082,7 +3109,7 @@ class SwaggerToApipost {
3082
3109
  },
3083
3110
  });
3084
3111
  }
3085
- else if (status == 404) {
3112
+ else if (String(status) == '404') {
3086
3113
  response.example.push({
3087
3114
  example_id: "2",
3088
3115
  raw: Raw_text,
@@ -5748,7 +5775,8 @@ class HarToApipost {
5748
5775
  const host = ((_b = (_a = request === null || request === void 0 ? void 0 : request.headers) === null || _a === void 0 ? void 0 : _a.find((e) => (e === null || e === void 0 ? void 0 : e.name) === "Host")) === null || _b === void 0 ? void 0 : _b.value) || "";
5749
5776
  const url = getUrlAfterSubstring((request === null || request === void 0 ? void 0 : request.url) || "", host);
5750
5777
  if ((item === null || item === void 0 ? void 0 : item._resourceType) === "xhr" ||
5751
- (item === null || item === void 0 ? void 0 : item._resourceType) === "preflight") {
5778
+ (item === null || item === void 0 ? void 0 : item._resourceType) === "preflight" ||
5779
+ (!lodash.has(item, '_resourceType') && lodash.isPlainObject(request))) {
5752
5780
  pre.push({
5753
5781
  target_id: apipostTools.snowflakeId(),
5754
5782
  project_id: this.project.project_id || "",
@@ -6544,13 +6572,13 @@ class PostmanToApipost {
6544
6572
  pre.push({
6545
6573
  param_id: apipostTools.snowflakeId(),
6546
6574
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
6547
- field_type: DEFAULT_FIELD_TYPE.includes(item === null || item === void 0 ? void 0 : item.type)
6575
+ field_type: DEFAULT_FIELD_TYPE.includes(item === null || item === void 0 ? void 0 : item.type) && lodash.isString(item === null || item === void 0 ? void 0 : item.type)
6548
6576
  ? item.type.charAt(0).toUpperCase() + item.type.slice(1)
6549
6577
  : "String",
6550
6578
  is_checked: (item === null || item === void 0 ? void 0 : item.disabled) ? -1 : 1,
6551
6579
  key: (item === null || item === void 0 ? void 0 : item.key) || "",
6552
6580
  value: (item === null || item === void 0 ? void 0 : item.value) || "",
6553
- not_null: -1,
6581
+ not_null: 1,
6554
6582
  });
6555
6583
  return pre;
6556
6584
  }, []);
@@ -6596,8 +6624,11 @@ class PostmanToApipost {
6596
6624
  break;
6597
6625
  }
6598
6626
  params["raw"] = lodash.isString(body === null || body === void 0 ? void 0 : body.raw) ? getBeautifulRaw(body === null || body === void 0 ? void 0 : body.raw) : "";
6599
- if (apipostTools.isJson(params["raw"])) {
6600
- params.raw_schema = toJsonSchemasecond__default["default"](JSON.parse(params["raw"]));
6627
+ if (apipostTools.isJson5(params["raw"])) {
6628
+ try {
6629
+ params.raw_schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(params["raw"]));
6630
+ }
6631
+ catch (error) { }
6601
6632
  }
6602
6633
  }
6603
6634
  }
@@ -6717,6 +6748,132 @@ class PostmanToApipost {
6717
6748
  },
6718
6749
  };
6719
6750
  }
6751
+ completionApiResponse(item, { response }) {
6752
+ const example = [
6753
+ {
6754
+ example_id: "1",
6755
+ expect: {
6756
+ code: "200",
6757
+ content_type: "json",
6758
+ is_default: 1,
6759
+ mock: "",
6760
+ name: "成功",
6761
+ schema: {
6762
+ type: "object",
6763
+ properties: {},
6764
+ },
6765
+ verify_type: "schema",
6766
+ },
6767
+ raw: "",
6768
+ raw_parameter: [],
6769
+ },
6770
+ {
6771
+ example_id: "2",
6772
+ expect: {
6773
+ code: "404",
6774
+ content_type: "json",
6775
+ is_default: -1,
6776
+ mock: "",
6777
+ name: "失败",
6778
+ schema: {
6779
+ type: "object",
6780
+ properties: {},
6781
+ },
6782
+ verify_type: "schema",
6783
+ },
6784
+ raw: "",
6785
+ raw_parameter: [],
6786
+ },
6787
+ ];
6788
+ if (isArray(response)) {
6789
+ let isOK = false;
6790
+ let isFailed = false;
6791
+ lodash.forEach(response, (item) => {
6792
+ let raw_schema = {
6793
+ type: "object",
6794
+ properties: {},
6795
+ };
6796
+ if (apipostTools.isJson5(item === null || item === void 0 ? void 0 : item["body"])) {
6797
+ try {
6798
+ raw_schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(item.body));
6799
+ }
6800
+ catch (error) { }
6801
+ }
6802
+ if ((item === null || item === void 0 ? void 0 : item.code) == 200 && !isOK) {
6803
+ isOK = true;
6804
+ example[0]['raw'] = (item === null || item === void 0 ? void 0 : item.body) || '';
6805
+ example[0].expect.name = getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255);
6806
+ example[0].expect.schema = raw_schema;
6807
+ if (isArray(item === null || item === void 0 ? void 0 : item.header)) {
6808
+ example[0].headers = item.header.map(i => {
6809
+ var _a;
6810
+ return {
6811
+ param_id: apipostTools.snowflakeId(),
6812
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6813
+ field_type: "String",
6814
+ is_checked: 1,
6815
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6816
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6817
+ not_null: 1,
6818
+ };
6819
+ });
6820
+ }
6821
+ }
6822
+ else if ((item === null || item === void 0 ? void 0 : item.code) == 404 && !isFailed) {
6823
+ isFailed = true;
6824
+ example[1]['raw'] = (item === null || item === void 0 ? void 0 : item.body) || '';
6825
+ example[1].expect.name = getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255);
6826
+ example[1].expect.schema = raw_schema;
6827
+ if (isArray(item === null || item === void 0 ? void 0 : item.header)) {
6828
+ example[1].headers = item.header.map(i => {
6829
+ var _a;
6830
+ return {
6831
+ param_id: apipostTools.snowflakeId(),
6832
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6833
+ field_type: "String",
6834
+ is_checked: 1,
6835
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6836
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6837
+ not_null: 1,
6838
+ };
6839
+ });
6840
+ }
6841
+ }
6842
+ else {
6843
+ example.push({
6844
+ example_id: apipostTools.snowflakeId(),
6845
+ raw: (item === null || item === void 0 ? void 0 : item.body) || '',
6846
+ raw_parameter: [],
6847
+ headers: isArray(item === null || item === void 0 ? void 0 : item.header) ? item.header.map(i => {
6848
+ var _a;
6849
+ return {
6850
+ param_id: apipostTools.snowflakeId(),
6851
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6852
+ field_type: "String",
6853
+ is_checked: 1,
6854
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6855
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6856
+ not_null: 1,
6857
+ };
6858
+ }) : [],
6859
+ expect: {
6860
+ name: getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255),
6861
+ code: getSubstring(String(item === null || item === void 0 ? void 0 : item.code), 128),
6862
+ content_type: "json",
6863
+ is_default: -1,
6864
+ mock: "",
6865
+ schema: raw_schema,
6866
+ verify_type: "schema",
6867
+ },
6868
+ });
6869
+ }
6870
+ });
6871
+ }
6872
+ return {
6873
+ is_check_result: 1,
6874
+ example: example,
6875
+ };
6876
+ }
6720
6877
  completionApiFolder(item, parentInfo) {
6721
6878
  return {
6722
6879
  target_id: apipostTools.snowflakeId(),
@@ -6736,7 +6893,7 @@ class PostmanToApipost {
6736
6893
  }
6737
6894
  completionApiTarget(item, parentInfo) {
6738
6895
  var _a, _b, _c;
6739
- const { request } = item || {};
6896
+ const { request, response } = item || {};
6740
6897
  if (lodash.isEqual((_a = request === null || request === void 0 ? void 0 : request.body) === null || _a === void 0 ? void 0 : _a.mode, 'graphql')) {
6741
6898
  return {
6742
6899
  target_id: apipostTools.snowflakeId(),
@@ -6753,45 +6910,9 @@ class PostmanToApipost {
6753
6910
  request,
6754
6911
  auth: (request === null || request === void 0 ? void 0 : request.auth) || {},
6755
6912
  }),
6756
- response: {
6757
- is_check_result: 1,
6758
- example: [
6759
- {
6760
- example_id: "1",
6761
- expect: {
6762
- code: "200",
6763
- content_type: "json",
6764
- is_default: 1,
6765
- mock: "",
6766
- name: "Success",
6767
- schema: {
6768
- type: "object",
6769
- properties: {},
6770
- },
6771
- verify_type: "schema",
6772
- },
6773
- raw: "",
6774
- raw_parameter: [],
6775
- },
6776
- {
6777
- example_id: "2",
6778
- expect: {
6779
- code: "404",
6780
- content_type: "json",
6781
- is_default: -1,
6782
- mock: "",
6783
- name: "Failed",
6784
- schema: {
6785
- type: "object",
6786
- properties: {},
6787
- },
6788
- verify_type: "schema",
6789
- },
6790
- raw: "",
6791
- raw_parameter: [],
6792
- },
6793
- ],
6794
- },
6913
+ response: this.completionApiResponse(item, {
6914
+ response
6915
+ }),
6795
6916
  attribute_info: {},
6796
6917
  tags: [],
6797
6918
  is_force: -1,
@@ -6814,45 +6935,9 @@ class PostmanToApipost {
6814
6935
  request,
6815
6936
  auth: (request === null || request === void 0 ? void 0 : request.auth) || {},
6816
6937
  }),
6817
- response: {
6818
- is_check_result: 1,
6819
- example: [
6820
- {
6821
- example_id: "1",
6822
- expect: {
6823
- code: "200",
6824
- content_type: "json",
6825
- is_default: 1,
6826
- mock: "",
6827
- name: "Success",
6828
- schema: {
6829
- type: "object",
6830
- properties: {},
6831
- },
6832
- verify_type: "schema",
6833
- },
6834
- raw: "",
6835
- raw_parameter: [],
6836
- },
6837
- {
6838
- example_id: "2",
6839
- expect: {
6840
- code: "404",
6841
- content_type: "json",
6842
- is_default: -1,
6843
- mock: "",
6844
- name: "Failed",
6845
- schema: {
6846
- type: "object",
6847
- properties: {},
6848
- },
6849
- verify_type: "schema",
6850
- },
6851
- raw: "",
6852
- raw_parameter: [],
6853
- },
6854
- ],
6855
- },
6938
+ response: this.completionApiResponse(item, {
6939
+ response
6940
+ }),
6856
6941
  attribute_info: {},
6857
6942
  tags: [],
6858
6943
  is_force: -1,
@@ -7028,7 +7113,7 @@ class YapiToApipost {
7028
7113
  body["raw"] = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.req_body_other) || "");
7029
7114
  if (apipostTools.isJson(body["raw"])) {
7030
7115
  try {
7031
- body["raw_schema"] = toJsonSchemasecond__default["default"](JSON.parse(body["raw"]));
7116
+ body["raw_schema"] = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(body["raw"]));
7032
7117
  }
7033
7118
  catch (error) { }
7034
7119
  }
@@ -7067,7 +7152,7 @@ class YapiToApipost {
7067
7152
  raw = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.res_body) || "");
7068
7153
  if (apipostTools.isJson(raw)) {
7069
7154
  try {
7070
- schema = toJsonSchemasecond__default["default"](JSON.parse(raw));
7155
+ schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(raw));
7071
7156
  }
7072
7157
  catch (error) { }
7073
7158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -39,6 +39,7 @@
39
39
  "fs": "^0.0.1-security",
40
40
  "i18next": "^24.2.3",
41
41
  "jest": "^29.7.0",
42
+ "json5": "^2.2.3",
42
43
  "lodash": "^4.17.21",
43
44
  "path": "^0.12.7",
44
45
  "swagger-client": "3.18.5",