echoapi-converter 0.0.63 → 0.0.65

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
  }
@@ -1125,11 +1125,7 @@ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
1125
1125
  if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
1126
1126
  item.key.length > 0 &&
1127
1127
  (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
1128
- lastData[item.key] = {
1129
- type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string',
1130
- description: (item === null || item === void 0 ? void 0 : item.description) || "",
1131
- example: (item === null || item === void 0 ? void 0 : item.value) || "",
1132
- };
1128
+ lastData[item.key] = Object.assign({ type: ((_a = item === null || item === void 0 ? void 0 : item.field_type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'string', description: (item === null || item === void 0 ? void 0 : item.description) || "", example: (item === null || item === void 0 ? void 0 : item.value) || "" }, (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.schema) ? item.schema : {}));
1133
1129
  }
1134
1130
  return lastData;
1135
1131
  }, {})
@@ -1317,6 +1313,9 @@ const transExample = (example) => {
1317
1313
  const getBeautifulRaw = (raw) => {
1318
1314
  var _a;
1319
1315
  try {
1316
+ if (!raw) {
1317
+ return raw;
1318
+ }
1320
1319
  return (_a = apipostTools.beautifyRaw(raw)) === null || _a === void 0 ? void 0 : _a.value;
1321
1320
  }
1322
1321
  catch (err) {
@@ -1386,7 +1385,7 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1386
1385
  url = `http://${url}`;
1387
1386
  }
1388
1387
  const urlObj = createUrl(url);
1389
- const paths = urlObj.pathname.split("/");
1388
+ const paths = urlObj.pathname.split('/');
1390
1389
  lodash.forEach(paths, (pathsItem) => {
1391
1390
  if (pathsItem.substring(0, 1) === ":" && pathsItem.length > 1) {
1392
1391
  let obj = null;
@@ -1398,12 +1397,13 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1398
1397
  }
1399
1398
  restfulList.push({
1400
1399
  param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
1401
- field_type: "String",
1400
+ field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
1402
1401
  is_checked: 1,
1403
1402
  key: pathsItem.substring(1, pathsItem.length),
1404
1403
  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) || "",
1404
+ value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
1405
+ description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
1406
+ schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
1407
1407
  });
1408
1408
  }
1409
1409
  });
@@ -1423,12 +1423,13 @@ const genRestfulByUrl = (url, oldParameter, key = "key") => {
1423
1423
  }
1424
1424
  restfulList.push({
1425
1425
  param_id: (obj === null || obj === void 0 ? void 0 : obj.param_id) || apipostTools.snowflakeId(),
1426
- field_type: "String",
1426
+ field_type: (obj === null || obj === void 0 ? void 0 : obj.field_type) || 'string',
1427
1427
  is_checked: 1,
1428
1428
  key: matchesItem,
1429
1429
  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) || "",
1430
+ value: (obj === null || obj === void 0 ? void 0 : obj.value) || '',
1431
+ description: (obj === null || obj === void 0 ? void 0 : obj.description) || '',
1432
+ schema: (obj === null || obj === void 0 ? void 0 : obj.schema) || {}
1432
1433
  });
1433
1434
  }
1434
1435
  });
@@ -2035,7 +2036,7 @@ const replaceRef = (schemaObj) => {
2035
2036
  // 如果当前属性的值是一个对象,则递归遍历该对象
2036
2037
  if (typeof value === 'object' && value !== null) {
2037
2038
  // 查找并替换 insAppInfo 对象
2038
- if (lodash.has(value, 'ref') || lodash.has(value, '$$ref')) {
2039
+ if (lodash.has(value, 'ref') || lodash.has(value, '$ref')) {
2039
2040
  let newIuid = apipostTools.snowflakeId();
2040
2041
  if ((value === null || value === void 0 ? void 0 : value.ref) && value.ref.startsWith('http://localhost:8000/')) {
2041
2042
  const index = (_a = value.ref) === null || _a === void 0 ? void 0 : _a.indexOf('#');
@@ -2046,7 +2047,7 @@ const replaceRef = (schemaObj) => {
2046
2047
  schemaObj[key] = {
2047
2048
  ['x-schema-refs']: {
2048
2049
  [newIuid]: {
2049
- ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$$ref'])
2050
+ ref: (value === null || value === void 0 ? void 0 : value.ref) || (value === null || value === void 0 ? void 0 : value['$ref'])
2050
2051
  },
2051
2052
  },
2052
2053
  properties: {},
@@ -2077,7 +2078,7 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
2077
2078
  jsonSchemaStr = jsonSchemaStr.replace(/\"x-apifox-overrides\"/g, '\"x-schema-overrides\"');
2078
2079
  // 还原为对象
2079
2080
  jsonSchema = JSON.parse(jsonSchemaStr);
2080
- if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$$ref')) {
2081
+ if (lodash.has(jsonSchema, 'ref') || lodash.has(jsonSchema, '$ref')) {
2081
2082
  let newIuid = apipostTools.snowflakeId();
2082
2083
  if ((jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) && jsonSchema.ref.startsWith("http://localhost:8000/")) {
2083
2084
  // jsonSchema.ref = jsonSchema.ref.substring(22);
@@ -2089,7 +2090,7 @@ const swaggerSchema2apipostSchema = (schemaObj) => {
2089
2090
  jsonSchema = {
2090
2091
  ['x-schema-refs']: {
2091
2092
  [newIuid]: {
2092
- $ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$$ref'])
2093
+ $ref: (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema.ref) || (jsonSchema === null || jsonSchema === void 0 ? void 0 : jsonSchema['$ref'])
2093
2094
  },
2094
2095
  },
2095
2096
  properties: {},
@@ -2137,8 +2138,8 @@ const createNewModelData = (item, key, folder_name) => {
2137
2138
  var model = {
2138
2139
  model_id: `#/components/${folder_name}/${key}`,
2139
2140
  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) || '',
2141
+ // displayName:key || item?.title || '',
2142
+ // display_name:key || item?.title || '',
2142
2143
  model_type: 'model',
2143
2144
  description: (item === null || item === void 0 ? void 0 : item.description) || '',
2144
2145
  schema: {},
@@ -2166,6 +2167,17 @@ const getFidldType = (type) => {
2166
2167
  }
2167
2168
  return 'String';
2168
2169
  };
2170
+ const getExampleId = (status) => {
2171
+ if (status == 200) {
2172
+ return '1';
2173
+ }
2174
+ else if (status == 404) {
2175
+ return '2';
2176
+ }
2177
+ else {
2178
+ return apipostTools.snowflakeId();
2179
+ }
2180
+ };
2169
2181
 
2170
2182
  class SwaggerToApipost {
2171
2183
  constructor() {
@@ -2256,6 +2268,9 @@ class SwaggerToApipost {
2256
2268
  getBeautifulRaw(raw) {
2257
2269
  var _a;
2258
2270
  try {
2271
+ if (!raw) {
2272
+ return raw;
2273
+ }
2259
2274
  return (_a = apipostTools.beautifyRaw(raw)) === null || _a === void 0 ? void 0 : _a.value;
2260
2275
  }
2261
2276
  catch (err) {
@@ -2434,6 +2449,7 @@ class SwaggerToApipost {
2434
2449
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2435
2450
  field_type: getFidldType((_b = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _b === void 0 ? void 0 : _b.type), // 类型
2436
2451
  param_id: apipostTools.snowflakeId(),
2452
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2437
2453
  });
2438
2454
  }
2439
2455
  else if (parameter.in == "header") {
@@ -2454,6 +2470,7 @@ class SwaggerToApipost {
2454
2470
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2455
2471
  field_type: getFidldType((_d = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _d === void 0 ? void 0 : _d.type), // 类型
2456
2472
  param_id: apipostTools.snowflakeId(),
2473
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2457
2474
  });
2458
2475
  }
2459
2476
  else if (parameter.in == "path") {
@@ -2474,6 +2491,7 @@ class SwaggerToApipost {
2474
2491
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2475
2492
  field_type: getFidldType((_f = parameter === null || parameter === void 0 ? void 0 : parameter.schema) === null || _f === void 0 ? void 0 : _f.type), // 类型
2476
2493
  param_id: apipostTools.snowflakeId(),
2494
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2477
2495
  });
2478
2496
  }
2479
2497
  }
@@ -2518,6 +2536,7 @@ class SwaggerToApipost {
2518
2536
  ? item.type.charAt(0).toUpperCase() + item.type.slice(1)
2519
2537
  : "String",
2520
2538
  param_id: apipostTools.snowflakeId(),
2539
+ schema: (item === null || item === void 0 ? void 0 : item.schema) || {}
2521
2540
  });
2522
2541
  }
2523
2542
  }
@@ -2586,7 +2605,7 @@ class SwaggerToApipost {
2586
2605
  jsonSchema = element.schema;
2587
2606
  }
2588
2607
  // 成功响应示例
2589
- if (status == 200) {
2608
+ if (String(status) == '200') {
2590
2609
  response.example.push({
2591
2610
  example_id: "1",
2592
2611
  raw: Raw_text,
@@ -2602,7 +2621,7 @@ class SwaggerToApipost {
2602
2621
  },
2603
2622
  });
2604
2623
  }
2605
- else if (status == 404) {
2624
+ else if (String(status) == '404') {
2606
2625
  response.example.push({
2607
2626
  example_id: "2",
2608
2627
  raw: Raw_text,
@@ -2770,7 +2789,7 @@ class SwaggerToApipost {
2770
2789
  }
2771
2790
  else {
2772
2791
  response.example.push({
2773
- example_id: apipostTools.snowflakeId(),
2792
+ example_id: getExampleId(status),
2774
2793
  raw: "",
2775
2794
  raw_parameter: [],
2776
2795
  expect: {
@@ -2906,7 +2925,7 @@ class SwaggerToApipost {
2906
2925
  not_null: 1,
2907
2926
  description: "",
2908
2927
  field_type: "String",
2909
- param_id: apipostTools.snowflakeId(),
2928
+ param_id: apipostTools.snowflakeId()
2910
2929
  });
2911
2930
  }
2912
2931
  if (lodash.has(swaggerApi, "parameters")) {
@@ -2941,6 +2960,7 @@ class SwaggerToApipost {
2941
2960
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2942
2961
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2943
2962
  param_id: apipostTools.snowflakeId(),
2963
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2944
2964
  });
2945
2965
  }
2946
2966
  else if (parameter.in == "header") {
@@ -2961,6 +2981,7 @@ class SwaggerToApipost {
2961
2981
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2962
2982
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2963
2983
  param_id: apipostTools.snowflakeId(),
2984
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2964
2985
  });
2965
2986
  }
2966
2987
  else if (parameter.in == "path") {
@@ -2981,6 +3002,7 @@ class SwaggerToApipost {
2981
3002
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
2982
3003
  field_type: getFidldType(parameter === null || parameter === void 0 ? void 0 : parameter.type), // 类型
2983
3004
  param_id: apipostTools.snowflakeId(),
3005
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
2984
3006
  });
2985
3007
  }
2986
3008
  else if (parameter.in == "body") {
@@ -3030,6 +3052,7 @@ class SwaggerToApipost {
3030
3052
  description: anyToString(parameter === null || parameter === void 0 ? void 0 : parameter.description) || "", // 参数描述
3031
3053
  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
3054
  param_id: apipostTools.snowflakeId(),
3055
+ schema: (parameter === null || parameter === void 0 ? void 0 : parameter.schema) || {}
3033
3056
  });
3034
3057
  }
3035
3058
  }
@@ -3066,7 +3089,7 @@ class SwaggerToApipost {
3066
3089
  jsonSchema = element.schema;
3067
3090
  }
3068
3091
  // 成功响应示例
3069
- if (status == 200) {
3092
+ if (String(status) == '200') {
3070
3093
  response.example.push({
3071
3094
  example_id: "1",
3072
3095
  raw: Raw_text,
@@ -3082,7 +3105,7 @@ class SwaggerToApipost {
3082
3105
  },
3083
3106
  });
3084
3107
  }
3085
- else if (status == 404) {
3108
+ else if (String(status) == '404') {
3086
3109
  response.example.push({
3087
3110
  example_id: "2",
3088
3111
  raw: Raw_text,
@@ -5748,7 +5771,8 @@ class HarToApipost {
5748
5771
  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
5772
  const url = getUrlAfterSubstring((request === null || request === void 0 ? void 0 : request.url) || "", host);
5750
5773
  if ((item === null || item === void 0 ? void 0 : item._resourceType) === "xhr" ||
5751
- (item === null || item === void 0 ? void 0 : item._resourceType) === "preflight") {
5774
+ (item === null || item === void 0 ? void 0 : item._resourceType) === "preflight" ||
5775
+ (!lodash.has(item, '_resourceType') && lodash.isPlainObject(request))) {
5752
5776
  pre.push({
5753
5777
  target_id: apipostTools.snowflakeId(),
5754
5778
  project_id: this.project.project_id || "",
@@ -6544,13 +6568,13 @@ class PostmanToApipost {
6544
6568
  pre.push({
6545
6569
  param_id: apipostTools.snowflakeId(),
6546
6570
  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)
6571
+ 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
6572
  ? item.type.charAt(0).toUpperCase() + item.type.slice(1)
6549
6573
  : "String",
6550
6574
  is_checked: (item === null || item === void 0 ? void 0 : item.disabled) ? -1 : 1,
6551
6575
  key: (item === null || item === void 0 ? void 0 : item.key) || "",
6552
6576
  value: (item === null || item === void 0 ? void 0 : item.value) || "",
6553
- not_null: -1,
6577
+ not_null: 1,
6554
6578
  });
6555
6579
  return pre;
6556
6580
  }, []);
@@ -6596,8 +6620,11 @@ class PostmanToApipost {
6596
6620
  break;
6597
6621
  }
6598
6622
  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"]));
6623
+ if (apipostTools.isJson5(params["raw"])) {
6624
+ try {
6625
+ params.raw_schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(params["raw"]));
6626
+ }
6627
+ catch (error) { }
6601
6628
  }
6602
6629
  }
6603
6630
  }
@@ -6717,6 +6744,132 @@ class PostmanToApipost {
6717
6744
  },
6718
6745
  };
6719
6746
  }
6747
+ completionApiResponse(item, { response }) {
6748
+ const example = [
6749
+ {
6750
+ example_id: "1",
6751
+ expect: {
6752
+ code: "200",
6753
+ content_type: "json",
6754
+ is_default: 1,
6755
+ mock: "",
6756
+ name: "成功",
6757
+ schema: {
6758
+ type: "object",
6759
+ properties: {},
6760
+ },
6761
+ verify_type: "schema",
6762
+ },
6763
+ raw: "",
6764
+ raw_parameter: [],
6765
+ },
6766
+ {
6767
+ example_id: "2",
6768
+ expect: {
6769
+ code: "404",
6770
+ content_type: "json",
6771
+ is_default: -1,
6772
+ mock: "",
6773
+ name: "失败",
6774
+ schema: {
6775
+ type: "object",
6776
+ properties: {},
6777
+ },
6778
+ verify_type: "schema",
6779
+ },
6780
+ raw: "",
6781
+ raw_parameter: [],
6782
+ },
6783
+ ];
6784
+ if (isArray(response)) {
6785
+ let isOK = false;
6786
+ let isFailed = false;
6787
+ lodash.forEach(response, (item) => {
6788
+ let raw_schema = {
6789
+ type: "object",
6790
+ properties: {},
6791
+ };
6792
+ if (apipostTools.isJson5(item === null || item === void 0 ? void 0 : item["body"])) {
6793
+ try {
6794
+ raw_schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(item.body));
6795
+ }
6796
+ catch (error) { }
6797
+ }
6798
+ if ((item === null || item === void 0 ? void 0 : item.code) == 200 && !isOK) {
6799
+ isOK = true;
6800
+ example[0]['raw'] = (item === null || item === void 0 ? void 0 : item.body) || '';
6801
+ example[0].expect.name = getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255);
6802
+ example[0].expect.schema = raw_schema;
6803
+ if (isArray(item === null || item === void 0 ? void 0 : item.header)) {
6804
+ example[0].headers = item.header.map(i => {
6805
+ var _a;
6806
+ return {
6807
+ param_id: apipostTools.snowflakeId(),
6808
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6809
+ field_type: "String",
6810
+ is_checked: 1,
6811
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6812
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6813
+ not_null: 1,
6814
+ };
6815
+ });
6816
+ }
6817
+ }
6818
+ else if ((item === null || item === void 0 ? void 0 : item.code) == 404 && !isFailed) {
6819
+ isFailed = true;
6820
+ example[1]['raw'] = (item === null || item === void 0 ? void 0 : item.body) || '';
6821
+ example[1].expect.name = getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255);
6822
+ example[1].expect.schema = raw_schema;
6823
+ if (isArray(item === null || item === void 0 ? void 0 : item.header)) {
6824
+ example[1].headers = item.header.map(i => {
6825
+ var _a;
6826
+ return {
6827
+ param_id: apipostTools.snowflakeId(),
6828
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6829
+ field_type: "String",
6830
+ is_checked: 1,
6831
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6832
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6833
+ not_null: 1,
6834
+ };
6835
+ });
6836
+ }
6837
+ }
6838
+ else {
6839
+ example.push({
6840
+ example_id: apipostTools.snowflakeId(),
6841
+ raw: (item === null || item === void 0 ? void 0 : item.body) || '',
6842
+ raw_parameter: [],
6843
+ headers: isArray(item === null || item === void 0 ? void 0 : item.header) ? item.header.map(i => {
6844
+ var _a;
6845
+ return {
6846
+ param_id: apipostTools.snowflakeId(),
6847
+ description: ((_a = i === null || i === void 0 ? void 0 : i.description) === null || _a === void 0 ? void 0 : _a.content) || "",
6848
+ field_type: "String",
6849
+ is_checked: 1,
6850
+ key: (i === null || i === void 0 ? void 0 : i.key) || "",
6851
+ value: (i === null || i === void 0 ? void 0 : i.value) || "",
6852
+ not_null: 1,
6853
+ };
6854
+ }) : [],
6855
+ expect: {
6856
+ name: getSubstring((item === null || item === void 0 ? void 0 : item.name) || (item === null || item === void 0 ? void 0 : item.status), 255),
6857
+ code: getSubstring(String(item === null || item === void 0 ? void 0 : item.code), 128),
6858
+ content_type: "json",
6859
+ is_default: -1,
6860
+ mock: "",
6861
+ schema: raw_schema,
6862
+ verify_type: "schema",
6863
+ },
6864
+ });
6865
+ }
6866
+ });
6867
+ }
6868
+ return {
6869
+ is_check_result: 1,
6870
+ example: example,
6871
+ };
6872
+ }
6720
6873
  completionApiFolder(item, parentInfo) {
6721
6874
  return {
6722
6875
  target_id: apipostTools.snowflakeId(),
@@ -6736,7 +6889,7 @@ class PostmanToApipost {
6736
6889
  }
6737
6890
  completionApiTarget(item, parentInfo) {
6738
6891
  var _a, _b, _c;
6739
- const { request } = item || {};
6892
+ const { request, response } = item || {};
6740
6893
  if (lodash.isEqual((_a = request === null || request === void 0 ? void 0 : request.body) === null || _a === void 0 ? void 0 : _a.mode, 'graphql')) {
6741
6894
  return {
6742
6895
  target_id: apipostTools.snowflakeId(),
@@ -6753,45 +6906,9 @@ class PostmanToApipost {
6753
6906
  request,
6754
6907
  auth: (request === null || request === void 0 ? void 0 : request.auth) || {},
6755
6908
  }),
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
- },
6909
+ response: this.completionApiResponse(item, {
6910
+ response
6911
+ }),
6795
6912
  attribute_info: {},
6796
6913
  tags: [],
6797
6914
  is_force: -1,
@@ -6814,45 +6931,9 @@ class PostmanToApipost {
6814
6931
  request,
6815
6932
  auth: (request === null || request === void 0 ? void 0 : request.auth) || {},
6816
6933
  }),
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
- },
6934
+ response: this.completionApiResponse(item, {
6935
+ response
6936
+ }),
6856
6937
  attribute_info: {},
6857
6938
  tags: [],
6858
6939
  is_force: -1,
@@ -7028,7 +7109,7 @@ class YapiToApipost {
7028
7109
  body["raw"] = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.req_body_other) || "");
7029
7110
  if (apipostTools.isJson(body["raw"])) {
7030
7111
  try {
7031
- body["raw_schema"] = toJsonSchemasecond__default["default"](JSON.parse(body["raw"]));
7112
+ body["raw_schema"] = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(body["raw"]));
7032
7113
  }
7033
7114
  catch (error) { }
7034
7115
  }
@@ -7067,7 +7148,7 @@ class YapiToApipost {
7067
7148
  raw = getBeautifulRaw((item === null || item === void 0 ? void 0 : item.res_body) || "");
7068
7149
  if (apipostTools.isJson(raw)) {
7069
7150
  try {
7070
- schema = toJsonSchemasecond__default["default"](JSON.parse(raw));
7151
+ schema = toJsonSchemasecond__default["default"](JSON5__default["default"].parse(raw));
7071
7152
  }
7072
7153
  catch (error) { }
7073
7154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.63",
3
+ "version": "0.0.65",
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",