echoapi-converter 0.0.44 → 0.0.46

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 +602 -206
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -256,65 +256,178 @@ const THUNDER_CLIENT_GRANT_TYPES = {
256
256
  "authorization_code": "authorization_code",
257
257
  "authorization_code_with_pkce": "authorization_code_with_pkce"
258
258
  };
259
+ // export const CONTENT_TYPES: Record<string, string> = {
260
+ // none: 'none',
261
+ // 'form-data': 'multipart/form-data',
262
+ // urlencoded: 'application/x-www-form-urlencoded',
263
+ // json: 'application/json',
264
+ // xml: 'application/xml',
265
+ // javascript: 'application/javascript',
266
+ // plain: 'text/plain',
267
+ // html: 'text/html',
268
+ // };
269
+ const FILL_TYPES = {
270
+ left: '左填充',
271
+ right: '右填充'
272
+ };
273
+ const RULE_TYPES_ICON = {
274
+ 1: '(,)',
275
+ 2: '(|)',
276
+ 3: '(;)',
277
+ 4: '(\\t)',
278
+ 5: '( )',
279
+ 6: '(:)',
280
+ 7: '(\\n)',
281
+ 8: '(\\r)',
282
+ 9: '(\\r\\n)',
283
+ };
259
284
 
260
285
  // @ts-nocheck
261
- const splicedPath = (name, version) => {
262
- if (version === "2.0") {
286
+ const MAX_DEEP_COUNT = 10;
287
+ const schemaPath = (name, version) => {
288
+ if (version === '2.0') {
263
289
  return `#/definitions/${name}`;
264
290
  }
265
291
  return `#/components/schemas/${name}`;
266
292
  };
267
- const deepHandleModelRef = (modelObj, modelsObj, version) => {
268
- var _a, _b, _c;
269
- const result = modelObj;
270
- // 遍历所有属性
271
- for (const key in modelObj) {
272
- if (lodash.has(modelObj, key)) {
273
- const value = modelObj[key];
274
- // 如果属性名为 "ECHOAPI_REFS"
275
- if (key === "ECHOAPI_REFS") {
276
- const lonely = !lodash.has(modelObj, "properties") || lodash.isEmpty(modelObj.properties);
277
- if (lodash.isPlainObject(value) && !lodash.isEmpty(value)) {
278
- const refArr = Object.keys(value);
279
- let modelPath = "";
280
- if (refArr.length > 1) {
281
- if (!lodash.has(modelObj, "properties")) {
282
- modelObj.properties = {};
293
+ const deepModelRef = (originSchema, schemaMap, startSchema, count = 0) => {
294
+ var _a, _b;
295
+ try {
296
+ let deepCount = lodash.cloneDeep(count);
297
+ const schema = lodash.cloneDeep(originSchema);
298
+ if (lodash.has(schema, 'ECHOAPI_REFS')) {
299
+ const refsValue = schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_REFS;
300
+ if (!lodash.isEmpty(refsValue) &&
301
+ Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
302
+ const properties = Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]'
303
+ ? schema === null || schema === void 0 ? void 0 : schema.properties
304
+ : {};
305
+ schema['properties'] = (_a = lodash.values(refsValue)) === null || _a === void 0 ? void 0 : _a.reduce((pre, item) => {
306
+ var _a, _b;
307
+ if ((item === null || item === void 0 ? void 0 : item.ref) &&
308
+ lodash.has(schemaMap, item === null || item === void 0 ? void 0 : item.ref) &&
309
+ !lodash.isEqual(startSchema || originSchema, (_a = schemaMap[item === null || item === void 0 ? void 0 : item.ref]) === null || _a === void 0 ? void 0 : _a.schema)) {
310
+ const mapValue = schemaMap[item === null || item === void 0 ? void 0 : item.ref];
311
+ if (mapValue && (mapValue === null || mapValue === void 0 ? void 0 : mapValue.name)) {
312
+ // 暂时没找到多ref引用的方案 先直接导出数据
313
+ // pre[mapValue?.name] = {
314
+ // $ref: mapValue?.path,
315
+ // };
316
+ let mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
317
+ if (lodash.has(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, 'APIPOST_REFS')) {
318
+ if (deepCount > MAX_DEEP_COUNT) {
319
+ mapSchema = mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema;
320
+ }
321
+ else {
322
+ mapSchema = deepModelRef(mapValue === null || mapValue === void 0 ? void 0 : mapValue.schema, schemaMap, startSchema || originSchema, ++deepCount);
323
+ }
324
+ }
325
+ pre = Object.assign(Object.assign({}, pre), ((mapSchema === null || mapSchema === void 0 ? void 0 : mapSchema.properties) || {}));
283
326
  }
284
- refArr.forEach((item) => {
285
- var _a;
286
- const modelObjItem = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[(_a = value === null || value === void 0 ? void 0 : value[item]) === null || _a === void 0 ? void 0 : _a.ref];
287
- modelPath = splicedPath(modelObjItem === null || modelObjItem === void 0 ? void 0 : modelObjItem.modelPath, version);
288
- modelObj.properties["$ref"] = modelPath;
289
- });
327
+ if (lodash.isEqual(startSchema || originSchema, (_b = schemaMap[item === null || item === void 0 ? void 0 : item.ref]) === null || _b === void 0 ? void 0 : _b.schema)) {
328
+ pre = {};
329
+ }
330
+ }
331
+ return pre;
332
+ }, properties);
333
+ }
334
+ }
335
+ if (lodash.has(schema, 'properties') &&
336
+ Object.prototype.toString.call(schema === null || schema === void 0 ? void 0 : schema.properties) === '[object Object]') {
337
+ let properties_keys = lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties);
338
+ if (
339
+ // 优化展示顺序
340
+ (schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS) &&
341
+ lodash.isArray(schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS) &&
342
+ lodash.isEqual(lodash.sortBy(schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS), lodash.sortBy(lodash.keys(schema === null || schema === void 0 ? void 0 : schema.properties)))) {
343
+ properties_keys = schema === null || schema === void 0 ? void 0 : schema.ECHOAPI_ORDERS;
344
+ }
345
+ schema['properties'] = properties_keys === null || properties_keys === void 0 ? void 0 : properties_keys.reduce((pre, key) => {
346
+ if (key && !lodash.isEmpty(schema === null || schema === void 0 ? void 0 : schema.properties[key])) {
347
+ if (deepCount > MAX_DEEP_COUNT) {
348
+ pre[key] = schema === null || schema === void 0 ? void 0 : schema.properties[key];
290
349
  }
291
350
  else {
292
- const oldRef = (_a = value === null || value === void 0 ? void 0 : value[refArr[0]]) === null || _a === void 0 ? void 0 : _a.ref;
293
- const hasInvPath = (_b = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[oldRef]) === null || _b === void 0 ? void 0 : _b.modelPath;
294
- let modelPath = splicedPath((_c = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[oldRef]) === null || _c === void 0 ? void 0 : _c.modelPath, version);
295
- if (lonely && hasInvPath) {
296
- modelObj.$ref = modelPath;
297
- }
298
- else {
299
- refArr.forEach((item) => {
300
- var _a;
301
- const modelObjItem = modelsObj === null || modelsObj === void 0 ? void 0 : modelsObj[(_a = value === null || value === void 0 ? void 0 : value[item]) === null || _a === void 0 ? void 0 : _a.ref];
302
- modelPath = splicedPath(modelObjItem === null || modelObjItem === void 0 ? void 0 : modelObjItem.modelPath, version);
303
- modelObj.properties["$ref"] = modelPath;
304
- });
305
- }
351
+ pre[key] = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.properties[key], schemaMap, startSchema || originSchema, ++deepCount);
306
352
  }
307
353
  }
308
- }
309
- // 如果属性是一个对象,就递归查找
310
- else if (Object.prototype.toString.call(value) === "[object Object]" &&
311
- value !== null) {
312
- modelObj[key] = deepHandleModelRef(value, modelsObj, version);
354
+ return pre;
355
+ }, {});
356
+ }
357
+ if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' && lodash.has(schema, 'items')) {
358
+ if (lodash.has(schema === null || schema === void 0 ? void 0 : schema.items, 'properties') &&
359
+ Object.prototype.toString.call((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.properties) === '[object Object]') {
360
+ if (deepCount <= MAX_DEEP_COUNT) {
361
+ schema.items = deepModelRef(schema === null || schema === void 0 ? void 0 : schema.items, schemaMap, startSchema || originSchema, ++deepCount);
362
+ }
313
363
  }
314
364
  }
365
+ // 处理数组的引用
366
+ schema === null || schema === void 0 ? true : delete schema.ECHOAPI_ORDERS;
367
+ schema === null || schema === void 0 ? true : delete schema.ECHOAPI_REFS;
368
+ return schema;
369
+ }
370
+ catch (err) {
371
+ console.log(err.message, "deepModelRef error");
372
+ return originSchema;
315
373
  }
316
- return result;
317
374
  };
375
+ // export const deepHandleModelRef = (
376
+ // modelObj: any,
377
+ // modelsObj: any,
378
+ // version: string
379
+ // ) => {
380
+ // const result = modelObj;
381
+ // // 遍历所有属性
382
+ // for (const key in modelObj) {
383
+ // if (has(modelObj, key)) {
384
+ // const value = modelObj[key];
385
+ // // 如果属性名为 "APIPOST_REFS"
386
+ // if (key === "APIPOST_REFS") {
387
+ // const lonely =
388
+ // !has(modelObj, "properties") || isEmpty(modelObj.properties);
389
+ // if (isPlainObject(value) && !isEmpty(value)) {
390
+ // const refArr: any = Object.keys(value);
391
+ // let modelPath = "";
392
+ // if (refArr.length > 1) {
393
+ // if (!has(modelObj, "properties")) {
394
+ // modelObj.properties = {};
395
+ // }
396
+ // refArr.forEach((item: any) => {
397
+ // const modelObjItem = modelsObj?.[value?.[item]?.ref];
398
+ // modelPath = splicedPath(modelObjItem?.modelPath, version);
399
+ // modelObj.properties["$ref"] = modelPath;
400
+ // });
401
+ // } else {
402
+ // const oldRef = value?.[refArr[0]]?.ref;
403
+ // const hasInvPath = modelsObj?.[oldRef]?.modelPath;
404
+ // let modelPath = splicedPath(
405
+ // modelsObj?.[oldRef]?.modelPath,
406
+ // version
407
+ // );
408
+ // if (lonely && hasInvPath) {
409
+ // modelObj.$ref = modelPath;
410
+ // } else {
411
+ // refArr.forEach((item: any) => {
412
+ // const modelObjItem = modelsObj?.[value?.[item]?.ref];
413
+ // modelPath = splicedPath(modelObjItem?.modelPath, version);
414
+ // modelObj.properties["$ref"] = modelPath;
415
+ // });
416
+ // }
417
+ // }
418
+ // }
419
+ // }
420
+ // // 如果属性是一个对象,就递归查找
421
+ // else if (
422
+ // Object.prototype.toString.call(value) === "[object Object]" &&
423
+ // value !== null
424
+ // ) {
425
+ // modelObj[key] = deepHandleModelRef(value, modelsObj, version);
426
+ // }
427
+ // }
428
+ // }
429
+ // return result;
430
+ // };
318
431
  const removeQuery = (url) => {
319
432
  let path = url;
320
433
  try {
@@ -405,11 +518,12 @@ const handlePathItemBodyParameters = (body, pathItem, modelsObj) => {
405
518
  in: "body",
406
519
  name: "body",
407
520
  description: "",
408
- schema: (body === null || body === void 0 ? void 0 : body.raw_schema) || {},
521
+ schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
522
+ type: 'object'
523
+ }, modelsObj),
409
524
  type: "string",
410
525
  example: (body === null || body === void 0 ? void 0 : body.raw) || "",
411
526
  };
412
- obj = deepHandleModelRef(obj, modelsObj, "2.0");
413
527
  pathItem.parameters.push(obj);
414
528
  }
415
529
  else if (["multipart/form-data", "application/x-www-form-urlencoded"].includes(mode)) {
@@ -433,7 +547,138 @@ const handlePathItemBodyParameters = (body, pathItem, modelsObj) => {
433
547
  }
434
548
  }
435
549
  };
436
- const handlePathItemrequestBody = (body, pathItem) => {
550
+ const handleGraphqlRequestBody = (query_list, query_schema, pathItem, modelsObj) => {
551
+ if (lodash.isArray(query_list) && query_list.length > 0) {
552
+ if (!lodash.has(pathItem, "requestBody")) {
553
+ pathItem.requestBody = {
554
+ content: {},
555
+ 'x-schema': query_schema || {}
556
+ };
557
+ }
558
+ query_list.forEach(m => {
559
+ var _a, _b, _c;
560
+ const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
561
+ pathItem.requestBody.content[mode] = {
562
+ 'x-query': (m === null || m === void 0 ? void 0 : m.query) || '',
563
+ 'x-variables': (m === null || m === void 0 ? void 0 : m.variables) || '',
564
+ 'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
565
+ 'x-response': {
566
+ 'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.response) === null || _a === void 0 ? void 0 : _a.mode) || '',
567
+ example: ((_b = m === null || m === void 0 ? void 0 : m.response) === null || _b === void 0 ? void 0 : _b.raw) || "",
568
+ schema: deepModelRef(((_c = m === null || m === void 0 ? void 0 : m.response) === null || _c === void 0 ? void 0 : _c.raw_schema) || {
569
+ type: "object",
570
+ }, modelsObj),
571
+ }
572
+ };
573
+ });
574
+ }
575
+ };
576
+ const handleSocketMethodParameterDescription = (item, mode) => {
577
+ let description = item === null || item === void 0 ? void 0 : item.description;
578
+ let rules = item === null || item === void 0 ? void 0 : item.rules;
579
+ if (mode == 'fixed_message') {
580
+ let fillTypStr = (FILL_TYPES === null || FILL_TYPES === void 0 ? void 0 : FILL_TYPES[rules === null || rules === void 0 ? void 0 : rules.fill_type]) || '';
581
+ return `${description}\n${fillTypStr}至长度${rules === null || rules === void 0 ? void 0 : rules.length},填充字符${rules === null || rules === void 0 ? void 0 : rules.custom}`;
582
+ }
583
+ else if (mode == 'delimiter_message') {
584
+ return `${description}\n结尾添加分隔符${RULE_TYPES_ICON[rules === null || rules === void 0 ? void 0 : rules.delimiter]}`;
585
+ }
586
+ return description;
587
+ };
588
+ const handleSocketMethodRequestBody = (body, pathItem) => {
589
+ if (lodash.isPlainObject(body) && !lodash.isEmpty(body)) {
590
+ if (!lodash.has(pathItem, "requestBody")) {
591
+ pathItem.requestBody = {
592
+ content: {},
593
+ };
594
+ }
595
+ const mode = MODE_TYPE[body === null || body === void 0 ? void 0 : body.mode];
596
+ const parameter = (body === null || body === void 0 ? void 0 : body.parameter) || [];
597
+ if (['delimiter_message', 'fixed_message'].includes(body === null || body === void 0 ? void 0 : body.mode)) {
598
+ pathItem.requestBody.content[body === null || body === void 0 ? void 0 : body.mode] = {
599
+ 'x-mode': (body === null || body === void 0 ? void 0 : body.mode) || '',
600
+ schema: {
601
+ type: "object",
602
+ properties: parameter.reduce((lastData, item) => {
603
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
604
+ item.key.length > 0 &&
605
+ (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
606
+ lastData[item.key] = {
607
+ type: "string",
608
+ description: handleSocketMethodParameterDescription(item, body === null || body === void 0 ? void 0 : body.mode),
609
+ example: (item === null || item === void 0 ? void 0 : item.value) || "",
610
+ };
611
+ }
612
+ return lastData;
613
+ }, {}),
614
+ },
615
+ example: "",
616
+ };
617
+ }
618
+ else {
619
+ let modeStr = MODE_TYPE[mode];
620
+ if (modeStr) {
621
+ pathItem.requestBody.content[modeStr] = {
622
+ 'x-mode': modeStr || '',
623
+ schema: {
624
+ type: "object",
625
+ },
626
+ example: (body === null || body === void 0 ? void 0 : body.raw) || "",
627
+ };
628
+ }
629
+ }
630
+ }
631
+ };
632
+ const handleMessagePathItemrequestBody = (message, pathItem, modelsObj) => {
633
+ if (lodash.isArray(message) && message.length > 0) {
634
+ if (!lodash.has(pathItem, "requestBody")) {
635
+ pathItem.requestBody = {
636
+ content: {},
637
+ };
638
+ }
639
+ message.forEach(m => {
640
+ var _a, _b, _c, _d, _e, _f;
641
+ const mode = `x-${m === null || m === void 0 ? void 0 : m.param_id}`;
642
+ pathItem.requestBody.content[mode] = {
643
+ 'x-mode': ((_a = m === null || m === void 0 ? void 0 : m.request) === null || _a === void 0 ? void 0 : _a.mode) || '',
644
+ 'x-summary': (m === null || m === void 0 ? void 0 : m.name) || '',
645
+ schema: deepModelRef(((_b = m === null || m === void 0 ? void 0 : m.request) === null || _b === void 0 ? void 0 : _b.raw_schema) || {
646
+ type: "object",
647
+ }, modelsObj),
648
+ example: ((_c = m === null || m === void 0 ? void 0 : m.request) === null || _c === void 0 ? void 0 : _c.raw) || "",
649
+ 'x-response': {
650
+ 'x-mode': ((_d = m === null || m === void 0 ? void 0 : m.response) === null || _d === void 0 ? void 0 : _d.mode) || '',
651
+ example: ((_e = m === null || m === void 0 ? void 0 : m.response) === null || _e === void 0 ? void 0 : _e.raw) || "",
652
+ schema: deepModelRef(((_f = m === null || m === void 0 ? void 0 : m.response) === null || _f === void 0 ? void 0 : _f.raw_schema) || {
653
+ type: "object",
654
+ }, modelsObj),
655
+ }
656
+ };
657
+ });
658
+ }
659
+ };
660
+ const handlePathItemResponse = (response, modelsObj) => {
661
+ const temp_responses = {};
662
+ const example = (response === null || response === void 0 ? void 0 : response.example) || [];
663
+ if (lodash.isPlainObject(response)) {
664
+ example.forEach(({ expect, raw }) => {
665
+ const code = expect === null || expect === void 0 ? void 0 : expect.code;
666
+ if (lodash.isNumber(code) || lodash.isString(code)) {
667
+ temp_responses[code] = {
668
+ description: (expect === null || expect === void 0 ? void 0 : expect.name) || "",
669
+ content: {
670
+ [(MODE_TYPE === null || MODE_TYPE === void 0 ? void 0 : MODE_TYPE[expect === null || expect === void 0 ? void 0 : expect.content_type]) || "*/*"]: {
671
+ schema: deepModelRef((expect === null || expect === void 0 ? void 0 : expect.schema) || {}, modelsObj),
672
+ example: raw || '',
673
+ },
674
+ },
675
+ };
676
+ }
677
+ });
678
+ }
679
+ return temp_responses;
680
+ };
681
+ const handlePathItemRequestBody = (body, pathItem, modelsObj) => {
437
682
  if (lodash.isPlainObject(body) && !lodash.isEmpty(body) && (body === null || body === void 0 ? void 0 : body.mode) != "none") {
438
683
  if (!lodash.has(pathItem, "requestBody")) {
439
684
  pathItem.requestBody = {
@@ -450,9 +695,9 @@ const handlePathItemrequestBody = (body, pathItem) => {
450
695
  "text/html",
451
696
  ].includes(mode)) {
452
697
  pathItem.requestBody.content[mode] = {
453
- schema: (body === null || body === void 0 ? void 0 : body.raw_schema) || {
454
- type: "string",
455
- },
698
+ schema: deepModelRef((body === null || body === void 0 ? void 0 : body.raw_schema) || {
699
+ type: "object",
700
+ }, modelsObj),
456
701
  example: (body === null || body === void 0 ? void 0 : body.raw) || "",
457
702
  };
458
703
  }
@@ -462,19 +707,19 @@ const handlePathItemrequestBody = (body, pathItem) => {
462
707
  pathItem.requestBody.content[mode] = {
463
708
  schema: {
464
709
  type: "object",
710
+ properties: parameter.reduce((lastData, item) => {
711
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
712
+ item.key.length > 0 &&
713
+ (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
714
+ lastData[item.key] = {
715
+ type: "string",
716
+ description: (item === null || item === void 0 ? void 0 : item.description) || "",
717
+ example: (item === null || item === void 0 ? void 0 : item.value) || "",
718
+ };
719
+ }
720
+ return lastData;
721
+ }, {})
465
722
  },
466
- properties: parameter.reduce((lastData, item) => {
467
- if (lodash.isString(item === null || item === void 0 ? void 0 : item.key) &&
468
- item.key.length > 0 &&
469
- (!lodash.has(item, "is_checked") || (item === null || item === void 0 ? void 0 : item.is_checked) > 0)) {
470
- lastData[item.key] = {
471
- type: "string",
472
- description: (item === null || item === void 0 ? void 0 : item.description) || "",
473
- example: (item === null || item === void 0 ? void 0 : item.value) || "",
474
- };
475
- }
476
- return lastData;
477
- }, {}),
478
723
  };
479
724
  }
480
725
  }
@@ -484,25 +729,151 @@ const handlePathItemrequestBody = (body, pathItem) => {
484
729
  (pathItem === null || pathItem === void 0 ? void 0 : pathItem.requestBody) && delete pathItem.requestBody;
485
730
  }
486
731
  };
487
- const handelPathItemResponse = (response) => {
488
- const temp_responses = {};
489
- const example = (response === null || response === void 0 ? void 0 : response.example) || [];
490
- if (lodash.isPlainObject(response)) {
491
- example.forEach(({ expect }) => {
492
- const code = expect === null || expect === void 0 ? void 0 : expect.code;
493
- if (lodash.isNumber(code) || lodash.isString(code)) {
494
- temp_responses[code] = {
495
- description: (expect === null || expect === void 0 ? void 0 : expect.name) || "",
496
- content: {
497
- [(MODE_TYPE === null || MODE_TYPE === void 0 ? void 0 : MODE_TYPE[expect === null || expect === void 0 ? void 0 : expect.contentType]) || "*/*"]: {
498
- schema: (expect === null || expect === void 0 ? void 0 : expect.schema) || {},
499
- },
500
- },
501
- };
732
+ 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;
734
+ const path = recursiveFolderPath("", sourceObj, pid, pidName);
735
+ const pathItem = {
736
+ 'x-protocol': target_type || '',
737
+ summary: (item === null || item === void 0 ? void 0 : item.name) || "",
738
+ description: (item === null || item === void 0 ? void 0 : item.description) || "",
739
+ tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
740
+ };
741
+ if (lodash.isArray(item === null || item === void 0 ? void 0 : item.tags) && (item === null || item === void 0 ? void 0 : item.tags.length) > 0) {
742
+ pathItem['x-tags'] = item === null || item === void 0 ? void 0 : item.tags;
743
+ }
744
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.mark_id)) {
745
+ pathItem['x-mark-id'] = item === null || item === void 0 ? void 0 : item.mark_id;
746
+ }
747
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.updated_at)) {
748
+ pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.tags;
749
+ }
750
+ if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
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;
752
+ }
753
+ if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.attribute_info) && !lodash.isEmpty(item === null || item === void 0 ? void 0 : item.attribute_info)) {
754
+ pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
755
+ }
756
+ if ((item === null || item === void 0 ? void 0 : item.is_exampled) === 1) {
757
+ pathItem['x-exampled'] = item === null || item === void 0 ? void 0 : item.is_exampled;
758
+ }
759
+ if (['http', 'sse'].includes(target_type)) {
760
+ // 处理 Query 和 Header 参数
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);
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);
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
+ // 处理请求体参数(根据 Swagger 版本)
765
+ if (apiVersion === "2.0") {
766
+ handlePathItemBodyParameters(((_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.body) || {}, pathItem, modelsObj);
767
+ }
768
+ else {
769
+ handlePathItemRequestBody(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
770
+ }
771
+ // 添加路径标签
772
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
773
+ pathItem.tags = [...pathItem.tags, path];
774
+ }
775
+ // 处理响应
776
+ pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
777
+ }
778
+ else if (['websocket2', 'socketio', 'graphql'].includes(target_type)) {
779
+ // 拼接description
780
+ if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.config)) {
781
+ switch (target_type) {
782
+ case 'socketio':
783
+ pathItem.description = `${pathItem.description}
784
+ 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
+ break;
786
+ case 'websocket2':
787
+ pathItem.description = `${pathItem.description}
788
+ 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
+ break;
502
790
  }
503
- });
791
+ }
792
+ 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);
793
+ 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);
794
+ 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);
795
+ if (target_type == 'socketio')
796
+ 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);
797
+ // 处理请体
798
+ if (target_type == 'graphql') {
799
+ 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);
800
+ }
801
+ else {
802
+ handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
803
+ }
804
+ // 添加路径标签
805
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
806
+ pathItem.tags = [...pathItem.tags, path];
807
+ }
504
808
  }
505
- return temp_responses;
809
+ else if (target_type == 'socket_method') {
810
+ // 拼接description
811
+ const configs = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.configs;
812
+ if (lodash.isPlainObject(configs)) {
813
+ 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 ?
814
+ (_7 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _7 === void 0 ? void 0 : _7.request.map((r, index) => {
815
+ var _a;
816
+ let str = getTcpMethodFucString(r);
817
+ if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
818
+ return str + ',';
819
+ }
820
+ return str;
821
+ }) : ''}`;
822
+ 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) => {
823
+ var _a;
824
+ let str = getTcpMethodFucString(r);
825
+ if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
826
+ return str + ',';
827
+ }
828
+ return str + '。';
829
+ }) : '';
830
+ pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
831
+ }
832
+ handleSocketMethodRequestBody(((_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.body) || {}, pathItem);
833
+ // 处理响应
834
+ pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
835
+ // 添加路径标签
836
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
837
+ pathItem.tags = [...pathItem.tags, path];
838
+ }
839
+ }
840
+ else if (target_type == 'doc') {
841
+ // 添加路径标签
842
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
843
+ pathItem.tags = [...pathItem.tags, path];
844
+ }
845
+ }
846
+ return pathItem;
847
+ };
848
+ const getTcpMethodFucString = (func) => {
849
+ switch (func === null || func === void 0 ? void 0 : func.id) {
850
+ case 'addCharToPacketEnd':
851
+ return `Add a newline character at the end of each request message ${func === null || func === void 0 ? void 0 : func.option}`;
852
+ case 'calcLengthToPacketHeader':
853
+ return `Calculates the content length (excluding the header) and adds it to the header (in text format, the header byte length is ${func === null || func === void 0 ? void 0 : func.option})`;
854
+ case 'removePacketHeader':
855
+ return `The response packet needs to be stripped of its header (length ${func === null || func === void 0 ? void 0 : func.option} byte)`;
856
+ case 'removeWrapChar':
857
+ return `Removes the newline character at the end of the line ${func === null || func === void 0 ? void 0 : func.option}`;
858
+ case 'parseXmlToJson':
859
+ return 'And convert the content in XML format to JSON format';
860
+ }
861
+ return '';
862
+ };
863
+ const getSocketRequestStr = (end_func) => {
864
+ switch (end_func === null || end_func === void 0 ? void 0 : end_func.name) {
865
+ case 'none':
866
+ return `Data received deemed complete (subcontracting is not addressed`;
867
+ case 'endedChar':
868
+ return `Packet tail with special characters ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
869
+ case 'endedHexChar':
870
+ return `Packet tail with special characters (binary message) ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
871
+ case 'endedHeaderByteLength':
872
+ return `[header + packet body] format message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
873
+ case 'endedContentByteLength':
874
+ return `Fixed-length message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
875
+ }
876
+ return '';
506
877
  };
507
878
 
508
879
  const throwResult$1 = (status, message, data = '') => {
@@ -771,6 +1142,12 @@ const genUrlByQuery = (url, parameter, query_add_equal = 1) => {
771
1142
  newUrl = `${lodash.head(newUrl.split("?"))}${paramsStr ? "?" : ""}${paramsStr}${((_a = urlParse__default["default"](newUrl)) === null || _a === void 0 ? void 0 : _a.hash) || ""}`;
772
1143
  return newUrl;
773
1144
  };
1145
+ const getSubstring = (str, length) => {
1146
+ if (lodash.isString(str)) {
1147
+ return str.substring(0, length);
1148
+ }
1149
+ return str;
1150
+ };
774
1151
 
775
1152
  // @ts-nocheck
776
1153
  class ApipostToSwagger {
@@ -798,7 +1175,7 @@ class ApipostToSwagger {
798
1175
  this.apiToSwaggerVersion = "2.0";
799
1176
  }
800
1177
  handleProject() {
801
- const { name, intro } = this.apiToSwaggerOrigin.project || {};
1178
+ const { name, intro, marks, attributes } = this.apiToSwaggerOrigin.project || {};
802
1179
  this.apiToSwaggerResult.info = {
803
1180
  title: name || "New Project",
804
1181
  description: intro || "",
@@ -810,51 +1187,44 @@ class ApipostToSwagger {
810
1187
  else if (this.apiToSwaggerVersion == "3.0") {
811
1188
  this.apiToSwaggerResult.openapi = "3.0.0";
812
1189
  }
1190
+ if (lodash.isArray(marks) && marks.length > 0) {
1191
+ this.apiToSwaggerResult.info['x-marks'] = marks;
1192
+ }
1193
+ if (lodash.isArray(attributes) && attributes.length > 0) {
1194
+ this.apiToSwaggerResult.info['x-attributes'] = attributes;
1195
+ }
813
1196
  }
814
1197
  handleModels() {
815
- var _a;
1198
+ var _a, _b;
816
1199
  const version = this.apiToSwaggerVersion;
817
- let modelsObj = {};
818
- const models = (_a = this.apiToSwaggerOrigin.models) === null || _a === void 0 ? void 0 : _a.filter((item) => (item === null || item === void 0 ? void 0 : item.model_type) === "model");
819
- if (lodash.isArray(models) && models.length > 0) {
820
- const components = {
821
- schemas: {},
822
- };
823
- const modelsPathObj = {};
824
- modelsObj = models.reduce((lastObj, item) => {
825
- if (item === null || item === void 0 ? void 0 : item.model_id) {
826
- let modelPath = `${item === null || item === void 0 ? void 0 : item.name}`;
827
- if (lodash.has(modelsPathObj, modelPath)) {
828
- while (!lodash.has(modelsPathObj, modelPath)) {
829
- modelPath += "1";
830
- }
831
- }
832
- if (Object.isExtensible(item)) {
833
- item["modelPath"] = modelPath;
834
- }
835
- modelsPathObj[modelPath] = item;
836
- lastObj[item.model_id] = item;
837
- return lastObj;
838
- }
839
- }, {});
840
- components.schemas = Object.keys(modelsPathObj).reduce((lastObj, key) => {
841
- const modelObj = modelsPathObj[key];
842
- if (!lodash.has(modelObj, "schema") || !lodash.isPlainObject(modelObj.schema)) {
843
- modelObj.schema = {};
1200
+ const childModels = (_a = this.apiToSwaggerOrigin.models) === null || _a === void 0 ? void 0 : _a.filter((item) => (item === null || item === void 0 ? void 0 : item.model_type) === "model");
1201
+ // 声明一个schema映射表
1202
+ const schemaMap = childModels === null || childModels === void 0 ? void 0 : childModels.reduce((pre, item) => {
1203
+ if ((item === null || item === void 0 ? void 0 : item.model_id) && (item === null || item === void 0 ? void 0 : item.name)) {
1204
+ pre[item === null || item === void 0 ? void 0 : item.model_id] = {
1205
+ schema: (item === null || item === void 0 ? void 0 : item.schema) || { type: 'object', properties: {} },
1206
+ path: schemaPath(item === null || item === void 0 ? void 0 : item.name, version),
1207
+ name: (item === null || item === void 0 ? void 0 : item.name) || '',
1208
+ };
1209
+ }
1210
+ return pre;
1211
+ }, {});
1212
+ if (lodash.isArray(childModels) && childModels.length > 0) {
1213
+ const schemas = (_b = lodash.values(schemaMap)) === null || _b === void 0 ? void 0 : _b.reduce((pre, item) => {
1214
+ if ((item === null || item === void 0 ? void 0 : item.name) && (item === null || item === void 0 ? void 0 : item.schema)) {
1215
+ pre[item === null || item === void 0 ? void 0 : item.name] = deepModelRef(item === null || item === void 0 ? void 0 : item.schema, schemaMap);
844
1216
  }
845
- // modelObj.schema.title = modelObj?.display_name || '';
846
- // 处理完所有当前模型所有引用
847
- lastObj[key] = deepHandleModelRef(modelObj.schema, modelsObj, version);
848
- return lastObj;
1217
+ return pre;
849
1218
  }, {});
850
- if (version === "2.0") {
851
- this.apiToSwaggerResult.definitions = components.schemas;
1219
+ // 先不区分目录概念 把所有的schema都放在schemas目录下 后期加上schemas生成多目录
1220
+ if (version === '2.0') {
1221
+ this.apiToSwaggerResult.definitions = schemas;
852
1222
  }
853
- else if (version === "3.0") {
854
- this.apiToSwaggerResult.components = components;
1223
+ if (lodash.isEqual(version, '3.0') || lodash.isEqual(version, '3.0.0')) {
1224
+ this.apiToSwaggerResult.components = { schemas };
855
1225
  }
856
1226
  }
857
- return modelsObj;
1227
+ return schemaMap;
858
1228
  }
859
1229
  handleEnvs() {
860
1230
  const envs = this.apiToSwaggerOrigin.envs;
@@ -931,7 +1301,7 @@ class ApipostToSwagger {
931
1301
  this.apiToSwaggerResult.paths = tempPaths;
932
1302
  }
933
1303
  array2NamePathObj(idName = "id", pidName = "pid", modelsObj) {
934
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1304
+ var _a, _b, _c, _d, _e;
935
1305
  const items = this.apiToSwaggerOrigin.apis;
936
1306
  try {
937
1307
  const paths = {};
@@ -946,57 +1316,82 @@ class ApipostToSwagger {
946
1316
  if (!id || id == undefined) {
947
1317
  continue;
948
1318
  }
949
- if (item.target_type == "api") {
1319
+ if (['sse', 'api'].includes(item.target_type)) {
950
1320
  const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
951
- const path = recursiveFolderPath("", sourceObj, pid, pidName);
952
- const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
953
- item.path = path;
954
- if (!lodash.has(paths, temp_url)) {
1321
+ const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1322
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type == 'api' ? 'http' : item.target_type);
1323
+ if (!paths[temp_url])
955
1324
  paths[temp_url] = {};
956
- }
957
- if (!lodash.has(paths[temp_url], targetMethod)) {
958
- const pathItem = {
959
- summary: (item === null || item === void 0 ? void 0 : item.name) || "",
960
- description: (item === null || item === void 0 ? void 0 : item.description) || "",
961
- tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
962
- };
963
- handlePathItemParameters("query", ((_c = (_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.query) === null || _c === void 0 ? void 0 : _c.parameter) || [], pathItem);
964
- handlePathItemParameters("header", ((_e = (_d = item === null || item === void 0 ? void 0 : item.request) === null || _d === void 0 ? void 0 : _d.header) === null || _e === void 0 ? void 0 : _e.parameter) || [], pathItem);
965
- if (this.apiToSwaggerVersion == "2.0") {
966
- handlePathItemBodyParameters(((_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.body) || {}, pathItem, modelsObj);
967
- }
968
- else {
969
- handlePathItemrequestBody(((_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.body) || {}, pathItem);
970
- }
971
- pathItem.requestBody = deepHandleModelRef(pathItem.requestBody, modelsObj, this.apiToSwaggerVersion);
972
- if (path && path.length > 0 && !pathItem.tags.includes(path)) {
973
- pathItem.tags = [...pathItem.tags, path];
974
- }
975
- // 添加响应期望 responses
976
- pathItem.responses = handelPathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {});
977
- pathItem.responses = deepHandleModelRef(pathItem.responses, modelsObj, this.apiToSwaggerVersion);
1325
+ if (!paths[temp_url][targetMethod]) {
978
1326
  paths[temp_url][targetMethod] = pathItem;
979
1327
  }
980
- else if (path &&
981
- path.length > 0 &&
982
- !((_h = paths[temp_url][targetMethod]) === null || _h === void 0 ? void 0 : _h.tags.includes(path))) {
983
- (_j = paths[temp_url][targetMethod]) === null || _j === void 0 ? void 0 : _j.tags.push(path);
1328
+ else if (pathItem.tags.length > 0) {
1329
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
984
1330
  }
985
1331
  }
986
- else if (item.target_type == "folder") {
1332
+ else if (["folder", "socket"].includes(item.target_type)) {
987
1333
  const path = recursiveFolderPath(`${item === null || item === void 0 ? void 0 : item.name}`, sourceObj, pid, pidName);
988
1334
  item.path = path;
989
1335
  if (!lodash.has(folderObj, item === null || item === void 0 ? void 0 : item.name)) {
990
1336
  if (!this.apiToSwaggerResult.tags) {
991
1337
  this.apiToSwaggerResult.tags = [];
992
1338
  }
1339
+ // 收到数据即认为完成(不处理分包问题) none
1340
+ if (item.target_type === 'socket' && lodash.isPlainObject((_b = item === null || item === void 0 ? void 0 : item.request) === null || _b === void 0 ? void 0 : _b.end_func)) {
1341
+ item.description = `| Server address | Determine the completion mode of receiving packets |
1342
+ | --- | --- |
1343
+ | ${item === null || item === void 0 ? void 0 : item.url} | ${getSocketRequestStr((_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.end_func)}
1344
+ ${item.description}
1345
+ `;
1346
+ }
993
1347
  this.apiToSwaggerResult.tags.push({
994
1348
  name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
995
1349
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
1350
+ 'x-type': item.target_type,
1351
+ 'x-url': (item === null || item === void 0 ? void 0 : item.url) || ''
996
1352
  });
997
1353
  folderObj[item === null || item === void 0 ? void 0 : item.name] = item;
998
1354
  }
999
1355
  }
1356
+ else if (['websocket2', 'socketio', 'graphql'].includes(item.target_type)) {
1357
+ const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
1358
+ const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.target_id}`;
1359
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1360
+ if (!paths[temp_url])
1361
+ paths[temp_url] = {};
1362
+ if (!paths[temp_url][targetMethod]) {
1363
+ paths[temp_url][targetMethod] = pathItem;
1364
+ }
1365
+ else if (pathItem.tags.length > 0) {
1366
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1367
+ }
1368
+ }
1369
+ else if (item.target_type === 'socket_method') {
1370
+ const temp_url = (sourceObj === null || sourceObj === void 0 ? void 0 : sourceObj[pid]) && ((_d = sourceObj[pid]) === null || _d === void 0 ? void 0 : _d.url) ? (_e = sourceObj[pid]) === null || _e === void 0 ? void 0 : _e.url : `${item === null || item === void 0 ? void 0 : item.name}`;
1371
+ const targetMethod = `x-${item.target_id}`;
1372
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1373
+ if (!paths[temp_url])
1374
+ paths[temp_url] = {};
1375
+ if (!paths[temp_url][targetMethod]) {
1376
+ paths[temp_url][targetMethod] = pathItem;
1377
+ }
1378
+ else if (pathItem.tags.length > 0) {
1379
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1380
+ }
1381
+ }
1382
+ else if (item.target_type === 'doc') {
1383
+ const temp_url = `x-${item.target_id}`;
1384
+ const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.name}`;
1385
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1386
+ if (!paths[temp_url])
1387
+ paths[temp_url] = {};
1388
+ if (!paths[temp_url][targetMethod]) {
1389
+ paths[temp_url][targetMethod] = pathItem;
1390
+ }
1391
+ else if (pathItem.tags.length > 0) {
1392
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1393
+ }
1394
+ }
1000
1395
  }
1001
1396
  return {
1002
1397
  paths,
@@ -1035,9 +1430,9 @@ class ApipostToSwagger {
1035
1430
  // 处理项目信息
1036
1431
  this.handleProject();
1037
1432
  // 处理数据模型
1038
- const modelsObj = this.handleModels();
1433
+ const schemaMap = this.handleModels();
1039
1434
  // // 处理apis
1040
- this.handleApis(modelsObj);
1435
+ this.handleApis(schemaMap);
1041
1436
  // 处理环境信息
1042
1437
  this.handleEnvs();
1043
1438
  if (`${version}` === "metersphere") {
@@ -1046,6 +1441,7 @@ class ApipostToSwagger {
1046
1441
  return throwResult$1("success", "", this.apiToSwaggerResult);
1047
1442
  }
1048
1443
  catch (error) {
1444
+ console.log(JSON.stringify(error.message), "error");
1049
1445
  return throwResult$1("error", String(error), this.apiToSwaggerResult);
1050
1446
  }
1051
1447
  }
@@ -1777,8 +2173,8 @@ class SwaggerToApipost {
1777
2173
  raw: Raw_text,
1778
2174
  raw_parameter: raw_parameter,
1779
2175
  expect: {
1780
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1781
- code: status,
2176
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2177
+ code: getSubstring(status, 128),
1782
2178
  content_type: "json",
1783
2179
  is_default: 1,
1784
2180
  mock: "",
@@ -1793,8 +2189,8 @@ class SwaggerToApipost {
1793
2189
  raw: Raw_text,
1794
2190
  raw_parameter: raw_parameter,
1795
2191
  expect: {
1796
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1797
- code: status,
2192
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2193
+ code: getSubstring(status, 128),
1798
2194
  content_type: "json",
1799
2195
  is_default: -1,
1800
2196
  mock: "",
@@ -1811,8 +2207,8 @@ class SwaggerToApipost {
1811
2207
  raw: Raw_text,
1812
2208
  raw_parameter: raw_parameter,
1813
2209
  expect: {
1814
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1815
- code: status,
2210
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2211
+ code: getSubstring(status, 128),
1816
2212
  content_type: "json",
1817
2213
  is_default: -1,
1818
2214
  mock: "",
@@ -1864,8 +2260,8 @@ class SwaggerToApipost {
1864
2260
  raw: Raw_text,
1865
2261
  raw_parameter: [],
1866
2262
  expect: {
1867
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1868
- code: status,
2263
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2264
+ code: getSubstring(status, 128),
1869
2265
  content_type: "json",
1870
2266
  is_default: status == 200 ? 1 : -1,
1871
2267
  mock: "",
@@ -1896,8 +2292,8 @@ class SwaggerToApipost {
1896
2292
  raw: Raw_text,
1897
2293
  raw_parameter: [],
1898
2294
  expect: {
1899
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1900
- code: status,
2295
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2296
+ code: getSubstring(status, 128),
1901
2297
  content_type: "json",
1902
2298
  is_default: -1,
1903
2299
  mock: "",
@@ -1921,8 +2317,8 @@ class SwaggerToApipost {
1921
2317
  raw: Raw_text,
1922
2318
  raw_parameter: raw_parameter,
1923
2319
  expect: {
1924
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1925
- code: status,
2320
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2321
+ code: getSubstring(status, 128),
1926
2322
  content_type: "json",
1927
2323
  is_default: status == 200 ? 1 : -1,
1928
2324
  mock: "",
@@ -1939,8 +2335,8 @@ class SwaggerToApipost {
1939
2335
  raw: Raw_text,
1940
2336
  raw_parameter: raw_parameter,
1941
2337
  expect: {
1942
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
1943
- code: status,
2338
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2339
+ code: getSubstring(status, 128),
1944
2340
  content_type: "json",
1945
2341
  is_default: -1,
1946
2342
  mock: "",
@@ -1959,8 +2355,8 @@ class SwaggerToApipost {
1959
2355
  raw: "",
1960
2356
  raw_parameter: [],
1961
2357
  expect: {
1962
- name: (element === null || element === void 0 ? void 0 : element.description) || status || "",
1963
- code: status,
2358
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status || "", 255),
2359
+ code: getSubstring(status, 128),
1964
2360
  content_type: "json",
1965
2361
  is_default: -1,
1966
2362
  mock: "",
@@ -2257,8 +2653,8 @@ class SwaggerToApipost {
2257
2653
  raw: Raw_text,
2258
2654
  raw_parameter: raw_parameter,
2259
2655
  expect: {
2260
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2261
- code: status,
2656
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2657
+ code: getSubstring(status, 128),
2262
2658
  content_type: "json",
2263
2659
  is_default: 1,
2264
2660
  mock: "",
@@ -2273,8 +2669,8 @@ class SwaggerToApipost {
2273
2669
  raw: Raw_text,
2274
2670
  raw_parameter: raw_parameter,
2275
2671
  expect: {
2276
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2277
- code: status,
2672
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2673
+ code: getSubstring(status, 128),
2278
2674
  content_type: "json",
2279
2675
  is_default: -1,
2280
2676
  mock: "",
@@ -2291,8 +2687,8 @@ class SwaggerToApipost {
2291
2687
  raw: Raw_text,
2292
2688
  raw_parameter: raw_parameter,
2293
2689
  expect: {
2294
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2295
- code: status,
2690
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2691
+ code: getSubstring(status, 128),
2296
2692
  content_type: "json",
2297
2693
  is_default: -1,
2298
2694
  mock: "",
@@ -2326,8 +2722,8 @@ class SwaggerToApipost {
2326
2722
  raw: Raw_text,
2327
2723
  raw_parameter: raw_parameter,
2328
2724
  expect: {
2329
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2330
- code: status,
2725
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2726
+ code: getSubstring(status, 128),
2331
2727
  content_type: "json",
2332
2728
  is_default: 1,
2333
2729
  mock: "",
@@ -2342,8 +2738,8 @@ class SwaggerToApipost {
2342
2738
  raw: Raw_text,
2343
2739
  raw_parameter: raw_parameter,
2344
2740
  expect: {
2345
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2346
- code: status,
2741
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2742
+ code: getSubstring(status, 128),
2347
2743
  content_type: "json",
2348
2744
  is_default: -1,
2349
2745
  mock: "",
@@ -2360,8 +2756,8 @@ class SwaggerToApipost {
2360
2756
  raw: Raw_text,
2361
2757
  raw_parameter: raw_parameter,
2362
2758
  expect: {
2363
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2364
- code: status,
2759
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2760
+ code: getSubstring(status, 128),
2365
2761
  content_type: "json",
2366
2762
  is_default: -1,
2367
2763
  mock: "",
@@ -2386,8 +2782,8 @@ class SwaggerToApipost {
2386
2782
  raw: "",
2387
2783
  raw_parameter: [],
2388
2784
  expect: {
2389
- name: (element === null || element === void 0 ? void 0 : element.description) || status,
2390
- code: status,
2785
+ name: getSubstring((element === null || element === void 0 ? void 0 : element.description) || status, 255),
2786
+ code: getSubstring(status, 128),
2391
2787
  content_type: "json",
2392
2788
  is_default: -1,
2393
2789
  mock: "",
@@ -2755,7 +3151,7 @@ class ApidocToApipost {
2755
3151
  project_id: this.project.project_id || "",
2756
3152
  parent_id: "0",
2757
3153
  target_type: "folder",
2758
- name: (item === null || item === void 0 ? void 0 : item.group) || "New Folder",
3154
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.group, 255) || "New Folder",
2759
3155
  version: 0,
2760
3156
  sort: 0,
2761
3157
  description: (item === null || item === void 0 ? void 0 : item.groupTitle) || "",
@@ -2771,7 +3167,7 @@ class ApidocToApipost {
2771
3167
  project_id: this.project.project_id || "",
2772
3168
  parent_id: id || "0",
2773
3169
  target_type: "api",
2774
- name: (item === null || item === void 0 ? void 0 : item.title) || "New HTTP",
3170
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.title, 255) || "New HTTP",
2775
3171
  version: 0,
2776
3172
  sort: 0,
2777
3173
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -2996,8 +3392,8 @@ class ApifoxToApipost {
2996
3392
  }
2997
3393
  initProject(json, project_id) {
2998
3394
  var _a, _b;
2999
- this.project.name = ((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name) || "New Project";
3000
- this.project.intro = ((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description) || "";
3395
+ this.project.name = getSubstring((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name, 64) || "New Project";
3396
+ this.project.intro = getSubstring((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description, 1024) || "";
3001
3397
  this.project.project_id = project_id;
3002
3398
  }
3003
3399
  completionParameter(parameter) {
@@ -3566,7 +3962,7 @@ class ApifoxToApipost {
3566
3962
  project_id: this.project.project_id || "",
3567
3963
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
3568
3964
  target_type: "folder",
3569
- name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
3965
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
3570
3966
  version: 0,
3571
3967
  sort: 0,
3572
3968
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -3602,9 +3998,9 @@ class ApifoxToApipost {
3602
3998
  raw: raw ? getBeautifulRaw((raw === null || raw === void 0 ? void 0 : raw.data) || "") : "",
3603
3999
  raw_parameter: [],
3604
4000
  expect: {
3605
- name: (item === null || item === void 0 ? void 0 : item.name) || "",
4001
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "",
3606
4002
  is_default: index === 0 ? 1 : -1,
3607
- code: (item === null || item === void 0 ? void 0 : item.code) && lodash.isNumber(item === null || item === void 0 ? void 0 : item.code) ? String(item === null || item === void 0 ? void 0 : item.code) : "",
4003
+ code: (item === null || item === void 0 ? void 0 : item.code) && lodash.isNumber(item === null || item === void 0 ? void 0 : item.code) ? getSubstring(String(item === null || item === void 0 ? void 0 : item.code), 128) : "",
3608
4004
  content_type: (DEFAULT_CONTENT_TYPE === null || DEFAULT_CONTENT_TYPE === void 0 ? void 0 : DEFAULT_CONTENT_TYPE.includes(item === null || item === void 0 ? void 0 : item.contentType))
3609
4005
  ? item === null || item === void 0 ? void 0 : item.contentType
3610
4006
  : "json",
@@ -3643,16 +4039,16 @@ class ApifoxToApipost {
3643
4039
  if (((_a = api === null || api === void 0 ? void 0 : api.requestBody) === null || _a === void 0 ? void 0 : _a.type) === 'graphql') {
3644
4040
  const request = this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody);
3645
4041
  const body = this.completionGraphqlRequestBody(api === null || api === void 0 ? void 0 : api.requestBody);
3646
- return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "graphql", name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), request: Object.assign(Object.assign({}, lodash.omit(request, ['body', 'query', 'restful'])), { body }), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
4042
+ return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "graphql", name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), request: Object.assign(Object.assign({}, lodash.omit(request, ['body', 'query', 'restful'])), { body }), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
3647
4043
  }
3648
- return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "api", name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", method: (api === null || api === void 0 ? void 0 : api.method) ? (_b = api === null || api === void 0 ? void 0 : api.method) === null || _b === void 0 ? void 0 : _b.toUpperCase() : "GET", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), protocol: "http/1.1", request: this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
4044
+ return Object.assign(Object.assign({}, baseInfo), { parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0", target_type: "api", name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP", version: 0, sort: 0, description: (api === null || api === void 0 ? void 0 : api.description) || "", method: (api === null || api === void 0 ? void 0 : api.method) ? (_b = api === null || api === void 0 ? void 0 : api.method) === null || _b === void 0 ? void 0 : _b.toUpperCase() : "GET", url: (api === null || api === void 0 ? void 0 : api.path) || "", mark_id: this.completionApiTargetMark(api === null || api === void 0 ? void 0 : api.status), protocol: "http/1.1", request: this.completionApiRequest(Object.assign(Object.assign({}, api === null || api === void 0 ? void 0 : api.parameters), { preProcessors: api === null || api === void 0 ? void 0 : api.preProcessors, postProcessors: api === null || api === void 0 ? void 0 : api.postProcessors, auth: api === null || api === void 0 ? void 0 : api.auth }), api === null || api === void 0 ? void 0 : api.requestBody), response: this.completionApiResponse(api === null || api === void 0 ? void 0 : api.responses, api === null || api === void 0 ? void 0 : api.responseExamples), attribute_info: {}, tags: isArray(api === null || api === void 0 ? void 0 : api.tags) ? api === null || api === void 0 ? void 0 : api.tags : [], is_force: -1 });
3649
4045
  }
3650
4046
  completionApiSample(item, baseInfo) {
3651
4047
  const { api } = item || {};
3652
4048
  const { cases } = api || {};
3653
4049
  return cases === null || cases === void 0 ? void 0 : cases.map((caseItem) => {
3654
4050
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
3655
- return Object.assign(Object.assign({}, baseInfo), { created_at: 0, method: (api === null || api === void 0 ? void 0 : api.method) ? (_a = api === null || api === void 0 ? void 0 : api.method) === null || _a === void 0 ? void 0 : _a.toUpperCase() : "GET", name: (caseItem === null || caseItem === void 0 ? void 0 : caseItem.name) || "New Test Case", parent_id: "0", protocol: "http/1.1", request: this.completionApiRequest({
4051
+ return Object.assign(Object.assign({}, baseInfo), { created_at: 0, method: (api === null || api === void 0 ? void 0 : api.method) ? (_a = api === null || api === void 0 ? void 0 : api.method) === null || _a === void 0 ? void 0 : _a.toUpperCase() : "GET", name: getSubstring(caseItem === null || caseItem === void 0 ? void 0 : caseItem.name, 255) || "New Test Case", parent_id: "0", protocol: "http/1.1", request: this.completionApiRequest({
3656
4052
  header: (_c = (((_b = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _b === void 0 ? void 0 : _b.header) || [])) === null || _c === void 0 ? void 0 : _c.concat(((_d = api === null || api === void 0 ? void 0 : api.parameters) === null || _d === void 0 ? void 0 : _d.header) || []),
3657
4053
  query: (_f = (((_e = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _e === void 0 ? void 0 : _e.query) || [])) === null || _f === void 0 ? void 0 : _f.concat(((_g = api === null || api === void 0 ? void 0 : api.parameters) === null || _g === void 0 ? void 0 : _g.query) || []),
3658
4054
  cookie: (_j = (((_h = caseItem === null || caseItem === void 0 ? void 0 : caseItem.parameters) === null || _h === void 0 ? void 0 : _h.cookie) || [])) === null || _j === void 0 ? void 0 : _j.concat(((_k = api === null || api === void 0 ? void 0 : api.parameters) === null || _k === void 0 ? void 0 : _k.cookie) || []),
@@ -4939,7 +5335,7 @@ class HarToApipost {
4939
5335
  project_id: this.project.project_id || "",
4940
5336
  parent_id: "0",
4941
5337
  target_type: "api",
4942
- name: url || "New HTTP",
5338
+ name: getSubstring(url, 255) || "New HTTP",
4943
5339
  version: 0,
4944
5340
  sort: 0,
4945
5341
  description: "",
@@ -5033,8 +5429,8 @@ class InsomniaToApipost {
5033
5429
  }
5034
5430
  initProject(resources, project_id) {
5035
5431
  const projectInfo = resources === null || resources === void 0 ? void 0 : resources.find((e) => (e === null || e === void 0 ? void 0 : e._type) === "workspace");
5036
- this.project.name = (projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.name) || "New Project";
5037
- this.project.intro = (projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.description) || "";
5432
+ this.project.name = getSubstring(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.name, 64) || "New Project";
5433
+ this.project.intro = getSubstring(projectInfo === null || projectInfo === void 0 ? void 0 : projectInfo.description, 1024) || "";
5038
5434
  this.project.project_id = project_id;
5039
5435
  }
5040
5436
  completionParameter(parameter) {
@@ -5235,7 +5631,7 @@ class InsomniaToApipost {
5235
5631
  parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
5236
5632
  description: (item === null || item === void 0 ? void 0 : item.description) || '',
5237
5633
  target_type: "websocket2",
5238
- name: (item === null || item === void 0 ? void 0 : item.name) || "New Websocket",
5634
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Websocket",
5239
5635
  sort: 0,
5240
5636
  version: 0,
5241
5637
  mark_id: "1",
@@ -5292,7 +5688,7 @@ class InsomniaToApipost {
5292
5688
  project_id: this.project.project_id || "",
5293
5689
  parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
5294
5690
  target_type: "graphql",
5295
- name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL",
5691
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL",
5296
5692
  version: 0,
5297
5693
  sort: 0,
5298
5694
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -5350,7 +5746,7 @@ class InsomniaToApipost {
5350
5746
  project_id: this.project.project_id || "",
5351
5747
  parent_id: ((_a = this.foldersMap) === null || _a === void 0 ? void 0 : _a[item === null || item === void 0 ? void 0 : item.parentId]) || "0",
5352
5748
  target_type: "api",
5353
- name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP",
5749
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP",
5354
5750
  version: 0,
5355
5751
  sort: 0,
5356
5752
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -5426,7 +5822,7 @@ class InsomniaToApipost {
5426
5822
  project_id: this.project.project_id || "",
5427
5823
  parent_id: this.foldersMap[item === null || item === void 0 ? void 0 : item.parentId] || "0",
5428
5824
  target_type: "folder",
5429
- name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
5825
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
5430
5826
  version: 0,
5431
5827
  sort: 0,
5432
5828
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -5905,7 +6301,7 @@ class PostmanToApipost {
5905
6301
  project_id: this.project.project_id || "",
5906
6302
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
5907
6303
  target_type: "folder",
5908
- name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
6304
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
5909
6305
  version: 0,
5910
6306
  sort: 0,
5911
6307
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -5925,7 +6321,7 @@ class PostmanToApipost {
5925
6321
  project_id: this.project.project_id || "",
5926
6322
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
5927
6323
  target_type: "graphql",
5928
- name: (item === null || item === void 0 ? void 0 : item.name) || "New GraphQL",
6324
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New GraphQL",
5929
6325
  version: 0,
5930
6326
  sort: 0,
5931
6327
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -5984,7 +6380,7 @@ class PostmanToApipost {
5984
6380
  project_id: this.project.project_id || "",
5985
6381
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
5986
6382
  target_type: "api",
5987
- name: (item === null || item === void 0 ? void 0 : item.name) || "New HTTP",
6383
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New HTTP",
5988
6384
  version: 0,
5989
6385
  sort: 0,
5990
6386
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -6066,8 +6462,8 @@ class PostmanToApipost {
6066
6462
  }
6067
6463
  initProject(json, project_id) {
6068
6464
  var _a, _b;
6069
- this.project.name = ((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name) || "New Project";
6070
- this.project.intro = ((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description) || "";
6465
+ this.project.name = getSubstring((_a = json === null || json === void 0 ? void 0 : json.info) === null || _a === void 0 ? void 0 : _a.name, 64) || "New Project";
6466
+ this.project.intro = getSubstring((_b = json === null || json === void 0 ? void 0 : json.info) === null || _b === void 0 ? void 0 : _b.description, 1024) || "";
6071
6467
  this.project.project_id = project_id;
6072
6468
  }
6073
6469
  convert(json, project_id, option) {
@@ -6126,7 +6522,7 @@ class YapiToApipost {
6126
6522
  project_id: this.project.project_id || "",
6127
6523
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
6128
6524
  target_type: "folder",
6129
- name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
6525
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.name, 255) || "New Folder",
6130
6526
  version: 0,
6131
6527
  sort: 0,
6132
6528
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
@@ -6298,7 +6694,7 @@ class YapiToApipost {
6298
6694
  project_id: this.project.project_id || "",
6299
6695
  parent_id: (parentInfo === null || parentInfo === void 0 ? void 0 : parentInfo.target_id) || "0",
6300
6696
  target_type: "api",
6301
- name: (item === null || item === void 0 ? void 0 : item.title) || "New HTTP",
6697
+ name: getSubstring(item === null || item === void 0 ? void 0 : item.title, 255) || "New HTTP",
6302
6698
  version: 0,
6303
6699
  sort: 0,
6304
6700
  description: (item === null || item === void 0 ? void 0 : item.desc) || "",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.44",
3
+ "version": "0.0.46",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [