echoapi-converter 0.0.45 → 0.0.47

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 +549 -157
  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) || {}));
326
+ }
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 = {};
283
329
  }
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
- });
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,152 @@ 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-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || '',
737
+ 'x-protocol': target_type || '',
738
+ summary: (item === null || item === void 0 ? void 0 : item.name) || "",
739
+ description: (item === null || item === void 0 ? void 0 : item.description) || "",
740
+ tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
741
+ };
742
+ if (lodash.isArray(item === null || item === void 0 ? void 0 : item.tags) && (item === null || item === void 0 ? void 0 : item.tags.length) > 0) {
743
+ pathItem['x-tags'] = item === null || item === void 0 ? void 0 : item.tags;
744
+ }
745
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.mark_id)) {
746
+ pathItem['x-mark-id'] = item === null || item === void 0 ? void 0 : item.mark_id;
747
+ }
748
+ if (lodash.isString(item === null || item === void 0 ? void 0 : item.updated_at)) {
749
+ pathItem['x-updated-at'] = item === null || item === void 0 ? void 0 : item.tags;
750
+ }
751
+ if (lodash.isString((_a = item === null || item === void 0 ? void 0 : item.updated_user) === null || _a === void 0 ? void 0 : _a.nick_name)) {
752
+ 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;
753
+ }
754
+ 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)) {
755
+ pathItem['x-attribute-info'] = item === null || item === void 0 ? void 0 : item.attribute_info;
756
+ }
757
+ if ((item === null || item === void 0 ? void 0 : item.is_exampled) === 1) {
758
+ pathItem['x-exampled'] = item === null || item === void 0 ? void 0 : item.is_exampled;
759
+ }
760
+ if (['http', 'sse'].includes(target_type)) {
761
+ // 处理 Query 和 Header 参数
762
+ handlePathItemParameters("query", ((_d = (_c = item === null || item === void 0 ? void 0 : item.request) === null || _c === void 0 ? void 0 : _c.query) === null || _d === void 0 ? void 0 : _d.parameter) || [], pathItem);
763
+ handlePathItemParameters("header", ((_f = (_e = item === null || item === void 0 ? void 0 : item.request) === null || _e === void 0 ? void 0 : _e.header) === null || _f === void 0 ? void 0 : _f.parameter) || [], pathItem);
764
+ 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);
765
+ // 处理请求体参数(根据 Swagger 版本)
766
+ if (apiVersion === "2.0") {
767
+ handlePathItemBodyParameters(((_j = item === null || item === void 0 ? void 0 : item.request) === null || _j === void 0 ? void 0 : _j.body) || {}, pathItem, modelsObj);
768
+ }
769
+ else {
770
+ handlePathItemRequestBody(((_k = item === null || item === void 0 ? void 0 : item.request) === null || _k === void 0 ? void 0 : _k.body) || {}, pathItem, modelsObj);
771
+ }
772
+ // 添加路径标签
773
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
774
+ pathItem.tags = [...pathItem.tags, path];
775
+ }
776
+ // 处理响应
777
+ pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
778
+ }
779
+ else if (['websocket2', 'socketio', 'graphql'].includes(target_type)) {
780
+ // 拼接description
781
+ if (lodash.isPlainObject(item === null || item === void 0 ? void 0 : item.config)) {
782
+ switch (target_type) {
783
+ case 'socketio':
784
+ pathItem.description = `${pathItem.description}
785
+ Over a secure connection,${((_l = item === null || item === void 0 ? void 0 : item.config) === null || _l === void 0 ? void 0 : _l.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},And use the client version ${((_m = item === null || item === void 0 ? void 0 : item.config) === null || _m === void 0 ? void 0 : _m.socket_version) || 'v4'}And the specified handshake path ${((_o = item === null || item === void 0 ? void 0 : item.config) === null || _o === void 0 ? void 0 : _o.shake_hands_path) || '/socket.io'} make a connection.`;
786
+ break;
787
+ case 'websocket2':
788
+ pathItem.description = `${pathItem.description}
789
+ Over a secure connection,${((_p = item === null || item === void 0 ? void 0 : item.config) === null || _p === void 0 ? void 0 : _p.certificate_verification) == -1 ? 'Do not enable server certificate verification.' : 'Enable server certificate verification'},${((_q = item === null || item === void 0 ? void 0 : item.config) === null || _q === void 0 ? void 0 : _q.information_size) == 0 ? 'And there is no limit to the maximum sent content that can be received。' : `And the maximum sent content allowed to be received is${((_r = item === null || item === void 0 ? void 0 : item.config) === null || _r === void 0 ? void 0 : _r.information_size) || 5}M。`}`;
790
+ break;
502
791
  }
503
- });
792
+ }
793
+ handlePathItemParameters("query", ((_t = (_s = item === null || item === void 0 ? void 0 : item.request) === null || _s === void 0 ? void 0 : _s.query) === null || _t === void 0 ? void 0 : _t.parameter) || [], pathItem);
794
+ handlePathItemParameters("header", ((_v = (_u = item === null || item === void 0 ? void 0 : item.request) === null || _u === void 0 ? void 0 : _u.header) === null || _v === void 0 ? void 0 : _v.parameter) || [], pathItem);
795
+ handlePathItemParameters("cookie", ((_x = (_w = item === null || item === void 0 ? void 0 : item.request) === null || _w === void 0 ? void 0 : _w.cookie) === null || _x === void 0 ? void 0 : _x.parameter) || [], pathItem);
796
+ if (target_type == 'socketio')
797
+ handlePathItemParameters("event", ((_z = (_y = item === null || item === void 0 ? void 0 : item.request) === null || _y === void 0 ? void 0 : _y.event) === null || _z === void 0 ? void 0 : _z.parameter) || [], pathItem);
798
+ // 处理请体
799
+ if (target_type == 'graphql') {
800
+ handleGraphqlRequestBody(((_1 = (_0 = item === null || item === void 0 ? void 0 : item.request) === null || _0 === void 0 ? void 0 : _0.body) === null || _1 === void 0 ? void 0 : _1.query_list) || [], ((_3 = (_2 = item === null || item === void 0 ? void 0 : item.request) === null || _2 === void 0 ? void 0 : _2.body) === null || _3 === void 0 ? void 0 : _3.query_schema) || {}, pathItem, modelsObj);
801
+ }
802
+ else {
803
+ handleMessagePathItemrequestBody((item === null || item === void 0 ? void 0 : item.message) || [], pathItem, modelsObj);
804
+ }
805
+ // 添加路径标签
806
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
807
+ pathItem.tags = [...pathItem.tags, path];
808
+ }
504
809
  }
505
- return temp_responses;
810
+ else if (target_type == 'socket_method') {
811
+ // 拼接description
812
+ const configs = (_4 = item === null || item === void 0 ? void 0 : item.request) === null || _4 === void 0 ? void 0 : _4.configs;
813
+ if (lodash.isPlainObject(configs)) {
814
+ let requestString = `The encoding format of the request packet is ${configs === null || configs === void 0 ? void 0 : configs.charset} ${lodash.isArray((_5 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _5 === void 0 ? void 0 : _5.request) && ((_6 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _6 === void 0 ? void 0 : _6.request.length) > 0 ?
815
+ (_7 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _7 === void 0 ? void 0 : _7.request.map((r, index) => {
816
+ var _a;
817
+ let str = getTcpMethodFucString(r);
818
+ if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
819
+ return str + ',';
820
+ }
821
+ return str;
822
+ }) : ''}`;
823
+ let responseString = lodash.isArray((_8 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _8 === void 0 ? void 0 : _8.response) && ((_9 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _9 === void 0 ? void 0 : _9.response.length) > 0 ? (_10 = configs === null || configs === void 0 ? void 0 : configs.func) === null || _10 === void 0 ? void 0 : _10.response.map((r, index) => {
824
+ var _a;
825
+ let str = getTcpMethodFucString(r);
826
+ if (index < ((_a = configs === null || configs === void 0 ? void 0 : configs.func) === null || _a === void 0 ? void 0 : _a.request.length) - 1) {
827
+ return str + ',';
828
+ }
829
+ return str + '。';
830
+ }) : '';
831
+ pathItem.description = `${pathItem.description}\n${requestString}\n${responseString}`;
832
+ }
833
+ handleSocketMethodRequestBody(((_11 = item === null || item === void 0 ? void 0 : item.request) === null || _11 === void 0 ? void 0 : _11.body) || {}, pathItem);
834
+ // 处理响应
835
+ pathItem.responses = handlePathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {}, modelsObj);
836
+ // 添加路径标签
837
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
838
+ pathItem.tags = [...pathItem.tags, path];
839
+ }
840
+ }
841
+ else if (target_type == 'doc') {
842
+ // 添加路径标签
843
+ if ((path === null || path === void 0 ? void 0 : path.length) > 0 && !pathItem.tags.includes(path)) {
844
+ pathItem.tags = [...pathItem.tags, path];
845
+ }
846
+ }
847
+ return pathItem;
848
+ };
849
+ const getTcpMethodFucString = (func) => {
850
+ switch (func === null || func === void 0 ? void 0 : func.id) {
851
+ case 'addCharToPacketEnd':
852
+ return `Add a newline character at the end of each request message ${func === null || func === void 0 ? void 0 : func.option}`;
853
+ case 'calcLengthToPacketHeader':
854
+ 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})`;
855
+ case 'removePacketHeader':
856
+ return `The response packet needs to be stripped of its header (length ${func === null || func === void 0 ? void 0 : func.option} byte)`;
857
+ case 'removeWrapChar':
858
+ return `Removes the newline character at the end of the line ${func === null || func === void 0 ? void 0 : func.option}`;
859
+ case 'parseXmlToJson':
860
+ return 'And convert the content in XML format to JSON format';
861
+ }
862
+ return '';
863
+ };
864
+ const getSocketRequestStr = (end_func) => {
865
+ switch (end_func === null || end_func === void 0 ? void 0 : end_func.name) {
866
+ case 'none':
867
+ return `Data received deemed complete (subcontracting is not addressed`;
868
+ case 'endedChar':
869
+ return `Packet tail with special characters ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
870
+ case 'endedHexChar':
871
+ return `Packet tail with special characters (binary message) ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
872
+ case 'endedHeaderByteLength':
873
+ return `[header + packet body] format message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
874
+ case 'endedContentByteLength':
875
+ return `Fixed-length message ${end_func === null || end_func === void 0 ? void 0 : end_func.option}`;
876
+ }
877
+ return '';
506
878
  };
507
879
 
508
880
  const throwResult$1 = (status, message, data = '') => {
@@ -804,7 +1176,7 @@ class ApipostToSwagger {
804
1176
  this.apiToSwaggerVersion = "2.0";
805
1177
  }
806
1178
  handleProject() {
807
- const { name, intro } = this.apiToSwaggerOrigin.project || {};
1179
+ const { name, intro, marks, attributes } = this.apiToSwaggerOrigin.project || {};
808
1180
  this.apiToSwaggerResult.info = {
809
1181
  title: name || "New Project",
810
1182
  description: intro || "",
@@ -816,51 +1188,44 @@ class ApipostToSwagger {
816
1188
  else if (this.apiToSwaggerVersion == "3.0") {
817
1189
  this.apiToSwaggerResult.openapi = "3.0.0";
818
1190
  }
1191
+ if (lodash.isArray(marks) && marks.length > 0) {
1192
+ this.apiToSwaggerResult.info['x-marks'] = marks;
1193
+ }
1194
+ if (lodash.isArray(attributes) && attributes.length > 0) {
1195
+ this.apiToSwaggerResult.info['x-attributes'] = attributes;
1196
+ }
819
1197
  }
820
1198
  handleModels() {
821
- var _a;
1199
+ var _a, _b;
822
1200
  const version = this.apiToSwaggerVersion;
823
- let modelsObj = {};
824
- 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");
825
- if (lodash.isArray(models) && models.length > 0) {
826
- const components = {
827
- schemas: {},
828
- };
829
- const modelsPathObj = {};
830
- modelsObj = models.reduce((lastObj, item) => {
831
- if (item === null || item === void 0 ? void 0 : item.model_id) {
832
- let modelPath = `${item === null || item === void 0 ? void 0 : item.name}`;
833
- if (lodash.has(modelsPathObj, modelPath)) {
834
- while (!lodash.has(modelsPathObj, modelPath)) {
835
- modelPath += "1";
836
- }
837
- }
838
- if (Object.isExtensible(item)) {
839
- item["modelPath"] = modelPath;
840
- }
841
- modelsPathObj[modelPath] = item;
842
- lastObj[item.model_id] = item;
843
- return lastObj;
844
- }
845
- }, {});
846
- components.schemas = Object.keys(modelsPathObj).reduce((lastObj, key) => {
847
- const modelObj = modelsPathObj[key];
848
- if (!lodash.has(modelObj, "schema") || !lodash.isPlainObject(modelObj.schema)) {
849
- modelObj.schema = {};
1201
+ 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");
1202
+ // 声明一个schema映射表
1203
+ const schemaMap = childModels === null || childModels === void 0 ? void 0 : childModels.reduce((pre, item) => {
1204
+ if ((item === null || item === void 0 ? void 0 : item.model_id) && (item === null || item === void 0 ? void 0 : item.name)) {
1205
+ pre[item === null || item === void 0 ? void 0 : item.model_id] = {
1206
+ schema: (item === null || item === void 0 ? void 0 : item.schema) || { type: 'object', properties: {} },
1207
+ path: schemaPath(item === null || item === void 0 ? void 0 : item.name, version),
1208
+ name: (item === null || item === void 0 ? void 0 : item.name) || '',
1209
+ };
1210
+ }
1211
+ return pre;
1212
+ }, {});
1213
+ if (lodash.isArray(childModels) && childModels.length > 0) {
1214
+ const schemas = (_b = lodash.values(schemaMap)) === null || _b === void 0 ? void 0 : _b.reduce((pre, item) => {
1215
+ if ((item === null || item === void 0 ? void 0 : item.name) && (item === null || item === void 0 ? void 0 : item.schema)) {
1216
+ pre[item === null || item === void 0 ? void 0 : item.name] = deepModelRef(item === null || item === void 0 ? void 0 : item.schema, schemaMap);
850
1217
  }
851
- // modelObj.schema.title = modelObj?.display_name || '';
852
- // 处理完所有当前模型所有引用
853
- lastObj[key] = deepHandleModelRef(modelObj.schema, modelsObj, version);
854
- return lastObj;
1218
+ return pre;
855
1219
  }, {});
856
- if (version === "2.0") {
857
- this.apiToSwaggerResult.definitions = components.schemas;
1220
+ // 先不区分目录概念 把所有的schema都放在schemas目录下 后期加上schemas生成多目录
1221
+ if (version === '2.0') {
1222
+ this.apiToSwaggerResult.definitions = schemas;
858
1223
  }
859
- else if (version === "3.0") {
860
- this.apiToSwaggerResult.components = components;
1224
+ if (lodash.isEqual(version, '3.0') || lodash.isEqual(version, '3.0.0')) {
1225
+ this.apiToSwaggerResult.components = { schemas };
861
1226
  }
862
1227
  }
863
- return modelsObj;
1228
+ return schemaMap;
864
1229
  }
865
1230
  handleEnvs() {
866
1231
  const envs = this.apiToSwaggerOrigin.envs;
@@ -937,7 +1302,7 @@ class ApipostToSwagger {
937
1302
  this.apiToSwaggerResult.paths = tempPaths;
938
1303
  }
939
1304
  array2NamePathObj(idName = "id", pidName = "pid", modelsObj) {
940
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1305
+ var _a, _b, _c, _d, _e;
941
1306
  const items = this.apiToSwaggerOrigin.apis;
942
1307
  try {
943
1308
  const paths = {};
@@ -952,57 +1317,83 @@ class ApipostToSwagger {
952
1317
  if (!id || id == undefined) {
953
1318
  continue;
954
1319
  }
955
- if (item.target_type == "api") {
1320
+ if (['sse', 'api'].includes(item.target_type)) {
956
1321
  const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
957
- const path = recursiveFolderPath("", sourceObj, pid, pidName);
958
- const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLocaleLowerCase();
959
- item.path = path;
960
- if (!lodash.has(paths, temp_url)) {
1322
+ const targetMethod = (_a = item === null || item === void 0 ? void 0 : item.method) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1323
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type == 'api' ? 'http' : item.target_type);
1324
+ if (!paths[temp_url])
961
1325
  paths[temp_url] = {};
962
- }
963
- if (!lodash.has(paths[temp_url], targetMethod)) {
964
- const pathItem = {
965
- summary: (item === null || item === void 0 ? void 0 : item.name) || "",
966
- description: (item === null || item === void 0 ? void 0 : item.description) || "",
967
- tags: (item === null || item === void 0 ? void 0 : item.tags) || [],
968
- };
969
- 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);
970
- 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);
971
- if (this.apiToSwaggerVersion == "2.0") {
972
- handlePathItemBodyParameters(((_f = item === null || item === void 0 ? void 0 : item.request) === null || _f === void 0 ? void 0 : _f.body) || {}, pathItem, modelsObj);
973
- }
974
- else {
975
- handlePathItemrequestBody(((_g = item === null || item === void 0 ? void 0 : item.request) === null || _g === void 0 ? void 0 : _g.body) || {}, pathItem);
976
- }
977
- pathItem.requestBody = deepHandleModelRef(pathItem.requestBody, modelsObj, this.apiToSwaggerVersion);
978
- if (path && path.length > 0 && !pathItem.tags.includes(path)) {
979
- pathItem.tags = [...pathItem.tags, path];
980
- }
981
- // 添加响应期望 responses
982
- pathItem.responses = handelPathItemResponse((item === null || item === void 0 ? void 0 : item.response) || {});
983
- pathItem.responses = deepHandleModelRef(pathItem.responses, modelsObj, this.apiToSwaggerVersion);
1326
+ if (!paths[temp_url][targetMethod]) {
984
1327
  paths[temp_url][targetMethod] = pathItem;
985
1328
  }
986
- else if (path &&
987
- path.length > 0 &&
988
- !((_h = paths[temp_url][targetMethod]) === null || _h === void 0 ? void 0 : _h.tags.includes(path))) {
989
- (_j = paths[temp_url][targetMethod]) === null || _j === void 0 ? void 0 : _j.tags.push(path);
1329
+ else if (pathItem.tags.length > 0) {
1330
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
990
1331
  }
991
1332
  }
992
- else if (item.target_type == "folder") {
1333
+ else if (["folder", "socket"].includes(item.target_type)) {
993
1334
  const path = recursiveFolderPath(`${item === null || item === void 0 ? void 0 : item.name}`, sourceObj, pid, pidName);
994
1335
  item.path = path;
995
1336
  if (!lodash.has(folderObj, item === null || item === void 0 ? void 0 : item.name)) {
996
1337
  if (!this.apiToSwaggerResult.tags) {
997
1338
  this.apiToSwaggerResult.tags = [];
998
1339
  }
1340
+ // 收到数据即认为完成(不处理分包问题) none
1341
+ 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)) {
1342
+ item.description = `| Server address | Determine the completion mode of receiving packets |
1343
+ | --- | --- |
1344
+ | ${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)}
1345
+ ${item.description}
1346
+ `;
1347
+ }
999
1348
  this.apiToSwaggerResult.tags.push({
1000
1349
  name: (item === null || item === void 0 ? void 0 : item.name) || "New Folder",
1001
1350
  description: (item === null || item === void 0 ? void 0 : item.description) || "",
1351
+ 'x-type': item.target_type,
1352
+ 'x-url': (item === null || item === void 0 ? void 0 : item.url) || '',
1353
+ 'x-target-id': (item === null || item === void 0 ? void 0 : item.target_id) || ''
1002
1354
  });
1003
1355
  folderObj[item === null || item === void 0 ? void 0 : item.name] = item;
1004
1356
  }
1005
1357
  }
1358
+ else if (['websocket2', 'socketio', 'graphql'].includes(item.target_type)) {
1359
+ const temp_url = removeQuery(item === null || item === void 0 ? void 0 : item.url);
1360
+ const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.target_id}`;
1361
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1362
+ if (!paths[temp_url])
1363
+ paths[temp_url] = {};
1364
+ if (!paths[temp_url][targetMethod]) {
1365
+ paths[temp_url][targetMethod] = pathItem;
1366
+ }
1367
+ else if (pathItem.tags.length > 0) {
1368
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1369
+ }
1370
+ }
1371
+ else if (item.target_type === 'socket_method') {
1372
+ 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}`;
1373
+ const targetMethod = `x-${item.target_id}`;
1374
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1375
+ if (!paths[temp_url])
1376
+ paths[temp_url] = {};
1377
+ if (!paths[temp_url][targetMethod]) {
1378
+ paths[temp_url][targetMethod] = pathItem;
1379
+ }
1380
+ else if (pathItem.tags.length > 0) {
1381
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1382
+ }
1383
+ }
1384
+ else if (item.target_type === 'doc') {
1385
+ const temp_url = `x-${item.target_id}`;
1386
+ const targetMethod = `x-${item === null || item === void 0 ? void 0 : item.name}`;
1387
+ const pathItem = createPathItem(item, sourceObj, pid, pidName, modelsObj, this.apiToSwaggerVersion, item.target_type);
1388
+ if (!paths[temp_url])
1389
+ paths[temp_url] = {};
1390
+ if (!paths[temp_url][targetMethod]) {
1391
+ paths[temp_url][targetMethod] = pathItem;
1392
+ }
1393
+ else if (pathItem.tags.length > 0) {
1394
+ paths[temp_url][targetMethod].tags.push(...pathItem.tags);
1395
+ }
1396
+ }
1006
1397
  }
1007
1398
  return {
1008
1399
  paths,
@@ -1041,9 +1432,9 @@ class ApipostToSwagger {
1041
1432
  // 处理项目信息
1042
1433
  this.handleProject();
1043
1434
  // 处理数据模型
1044
- const modelsObj = this.handleModels();
1435
+ const schemaMap = this.handleModels();
1045
1436
  // // 处理apis
1046
- this.handleApis(modelsObj);
1437
+ this.handleApis(schemaMap);
1047
1438
  // 处理环境信息
1048
1439
  this.handleEnvs();
1049
1440
  if (`${version}` === "metersphere") {
@@ -1052,6 +1443,7 @@ class ApipostToSwagger {
1052
1443
  return throwResult$1("success", "", this.apiToSwaggerResult);
1053
1444
  }
1054
1445
  catch (error) {
1446
+ console.log(JSON.stringify(error.message), "error");
1055
1447
  return throwResult$1("error", String(error), this.apiToSwaggerResult);
1056
1448
  }
1057
1449
  }
@@ -1574,8 +1966,8 @@ class SwaggerToApipost {
1574
1966
  }
1575
1967
  }
1576
1968
  handlePathV3(path, pathItem, tags) {
1577
- var _a, _b, _c, _d, _e, _f, _g, _h;
1578
1969
  return __awaiter(this, void 0, void 0, function* () {
1970
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1579
1971
  let url = path;
1580
1972
  for (const method in pathItem) {
1581
1973
  const swaggerApi = pathItem[method];
@@ -1992,8 +2384,8 @@ class SwaggerToApipost {
1992
2384
  });
1993
2385
  }
1994
2386
  handlePathsV3(json) {
1995
- var _a, _b;
1996
2387
  return __awaiter(this, void 0, void 0, function* () {
2388
+ var _a, _b;
1997
2389
  try {
1998
2390
  const paths = ((_a = json === null || json === void 0 ? void 0 : json.openapi) === null || _a === void 0 ? void 0 : _a.paths) || json.paths;
1999
2391
  const tags = ((_b = json === null || json === void 0 ? void 0 : json.openapi) === null || _b === void 0 ? void 0 : _b.tags) || json.tags;
@@ -2025,8 +2417,8 @@ class SwaggerToApipost {
2025
2417
  }
2026
2418
  }
2027
2419
  handlePath(path, pathItem, tags) {
2028
- var _a, _b, _c, _d, _e, _f, _g, _h;
2029
2420
  return __awaiter(this, void 0, void 0, function* () {
2421
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2030
2422
  let url = path;
2031
2423
  url = decodeURI(this.basePath + url);
2032
2424
  url = fixUrlPath(url);
@@ -2433,8 +2825,8 @@ class SwaggerToApipost {
2433
2825
  catch (err) { }
2434
2826
  });
2435
2827
  }
2436
- convert(json, options = null) {
2437
- return __awaiter(this, void 0, void 0, function* () {
2828
+ convert(json_1) {
2829
+ return __awaiter(this, arguments, void 0, function* (json, options = null) {
2438
2830
  this.clear();
2439
2831
  try {
2440
2832
  if (options && options instanceof Object) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "echoapi-converter",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "description": "echoapi to swagger",
5
5
  "main": "dist/index.js",
6
6
  "files": [