yapi-apifox-to-typescript 4.2.0 → 4.2.2

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.
@@ -68,6 +68,20 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
68
68
  return resolved.type || 'string';
69
69
  };
70
70
 
71
+ _proto.getRequestParamType = function getRequestParamType(schema) {
72
+ var schemaType = this.getSchemaType(schema);
73
+ if (schemaType === 'boolean') return _types.RequestParamType.boolean;
74
+ if (schemaType === 'number') return _types.RequestParamType.number;
75
+ return _types.RequestParamType.string;
76
+ };
77
+
78
+ _proto.getRequestQueryType = function getRequestQueryType(schema) {
79
+ var schemaType = this.getSchemaType(schema);
80
+ if (schemaType === 'boolean') return _types.RequestQueryType.boolean;
81
+ if (schemaType === 'number') return _types.RequestQueryType.number;
82
+ return _types.RequestQueryType.string;
83
+ };
84
+
71
85
  _proto.convertParametersToReqParams = function convertParametersToReqParams(parameters, type) {
72
86
  var _this = this;
73
87
 
@@ -84,7 +98,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
84
98
  desc: p.description || '',
85
99
  example: p.example || '',
86
100
  required: p.required ? _types.Required.true : _types.Required.false,
87
- type: _this.getSchemaType(p.schema) === 'string' ? _types.RequestParamType.string : _types.RequestParamType.number
101
+ type: _this.getRequestParamType(p.schema)
88
102
  };
89
103
  });
90
104
  }
@@ -97,7 +111,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
97
111
  desc: p.description || '',
98
112
  example: p.example || '',
99
113
  required: p.required ? _types.Required.true : _types.Required.false,
100
- type: _this.getSchemaType(p.schema) === 'string' ? _types.RequestQueryType.string : _types.RequestQueryType.number
114
+ type: _this.getRequestQueryType(p.schema)
101
115
  };
102
116
  });
103
117
  };
@@ -241,9 +255,30 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
241
255
  _proto.generateInterfaceId = function generateInterfaceId() {
242
256
  this.interfaceIdCounter += 1;
243
257
  return this.interfaceIdCounter;
258
+ }
259
+ /**
260
+ * 获取接口所属的目录名称
261
+ * Apifox 优先使用 x-apifox-folder 字段,其次才用 tags[0]
262
+ */
263
+ ;
264
+
265
+ _proto.getOperationFolder = function getOperationFolder(operation) {
266
+ // 优先使用 x-apifox-folder
267
+ if (operation['x-apifox-folder']) {
268
+ return operation['x-apifox-folder'];
269
+ } // 其次使用 tags[0]
270
+
271
+
272
+ if (operation.tags && operation.tags.length > 0) {
273
+ return operation.tags[0];
274
+ }
275
+
276
+ return 'default';
244
277
  };
245
278
 
246
279
  _proto.convertOperationToInterface = function convertOperationToInterface(path, method, operation, categoryName, categoryId) {
280
+ var _operation$tags;
281
+
247
282
  var parameters = operation.parameters || [];
248
283
  var pathParams = this.convertParametersToReqParams(parameters, 'path');
249
284
  var queryParams = this.convertParametersToReqParams(parameters, 'query'); // const headerParams = parameters.filter(p => p.in === 'header')
@@ -261,7 +296,10 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
261
296
  });
262
297
  }
263
298
 
264
- var responseInfo = this.convertResponse(operation.responses);
299
+ var responseInfo = this.convertResponse(operation.responses); // 获取接口所属目录:优先使用 x-apifox-folder,其次用 tags
300
+
301
+ var folderName = this.getOperationFolder(operation);
302
+ var interfaceTags = (_operation$tags = operation.tags) != null && _operation$tags.length ? operation.tags : folderName !== 'default' ? [folderName] : [];
265
303
  return {
266
304
  _id: this.generateInterfaceId(),
267
305
  _category: {
@@ -281,7 +319,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
281
319
  method: method.toUpperCase(),
282
320
  project_id: this.options.projectId,
283
321
  catid: categoryId,
284
- tag: operation.tags || [],
322
+ tag: interfaceTags,
285
323
  req_headers: reqHeaders,
286
324
  req_params: pathParams,
287
325
  req_query: queryParams,
@@ -315,7 +353,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
315
353
  excludedByTags: []
316
354
  },
317
355
  options: {
318
- includeApifoxExtensionProperties: false,
356
+ includeApifoxExtensionProperties: true,
319
357
  addFoldersToTags: (_this$options$addFold = this.options.addFoldersToTags) != null ? _this$options$addFold : true
320
358
  },
321
359
  oasVersion: (_this$options$oasVers = this.options.oasVersion) != null ? _this$options$oasVers : '3.0',
@@ -378,6 +416,25 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
378
416
  }
379
417
 
380
418
  return Math.abs(hash);
419
+ }
420
+ /**
421
+ * 从 OpenAPI tags 中获取目录对应的 tag
422
+ * 如果 x-apifox-folder 在 tags 中存在,则返回对应的 tag;否则返回 x-apifox-folder 本身
423
+ */
424
+ ;
425
+
426
+ _proto.getMatchingTag = function getMatchingTag(xApifoxFolder) {
427
+ var _this$openApiDoc4;
428
+
429
+ if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return null; // 先精确匹配
430
+
431
+ var exactMatch = this.openApiDoc.tags.find(function (tag) {
432
+ return tag.name === xApifoxFolder;
433
+ });
434
+ if (exactMatch) return exactMatch.name; // 如果 addFoldersToTags=true,可能目录名被添加到 tag 描述或其他地方
435
+ // 或者 tag.name 本身就包含了目录路径
436
+
437
+ return null;
381
438
  };
382
439
 
383
440
  _proto.getCats = function getCats(cats) {
@@ -386,12 +443,16 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
386
443
  var categoryIds = (0, _utils.getFilteredCat)(cats, [], true);
387
444
 
388
445
  if (categoryIds.length === 0 || categoryIds.includes(0)) {
389
- var _this$openApiDoc4;
446
+ var _this$openApiDoc5;
390
447
 
391
- if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return [];
392
- return this.openApiDoc.tags.map(function (tag) {
448
+ if (!((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.tags)) {
449
+ return [];
450
+ }
451
+
452
+ var tagIds = this.openApiDoc.tags.map(function (tag) {
393
453
  return _this2.getTagId(tag.name);
394
454
  });
455
+ return tagIds;
395
456
  }
396
457
 
397
458
  return categoryIds;
@@ -399,15 +460,15 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
399
460
 
400
461
  _proto.getInterfaceList = /*#__PURE__*/function () {
401
462
  var _getInterfaceList = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syntheticalConfig) {
402
- var _this$openApiDoc5;
463
+ var _this$openApiDoc6;
403
464
 
404
- var catId, interfaces, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, operationTags, _iterator2, _step2, tag, tagId, interfaceInfo;
465
+ var catId, interfaces, seenKeys, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
405
466
 
406
467
  return _regenerator.default.wrap(function _callee2$(_context2) {
407
468
  while (1) {
408
469
  switch (_context2.prev = _context2.next) {
409
470
  case 0:
410
- if ((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.paths) {
471
+ if ((_this$openApiDoc6 = this.openApiDoc) != null && _this$openApiDoc6.paths) {
411
472
  _context2.next = 2;
412
473
  break;
413
474
  }
@@ -416,27 +477,32 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
416
477
 
417
478
  case 2:
418
479
  catId = syntheticalConfig.id;
419
- interfaces = []; // let categoryName = ''
420
- // if (this.openApiDoc.tags) {
421
- // const tag = this.openApiDoc.tags.find(t => this.getTagId(t.name) === catId)
422
- // categoryName = tag?.name || ''
480
+ interfaces = []; // 用于去重:基于 path + method
481
+
482
+ seenKeys = new Set(); // 调试:获取 tag 名称
483
+ // let tagName = 'unknown'
484
+ // if (this.openApiDoc?.tags) {
485
+ // const tag = this.openApiDoc.tags.find(
486
+ // t => this.getTagId(t.name) === catId,
487
+ // )
488
+ // tagName = tag?.name || `unknown(${catId})`
423
489
  // }
424
490
 
425
491
  methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
426
492
  _i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
427
493
 
428
- case 6:
494
+ case 7:
429
495
  if (!(_i3 < _Object$entries3.length)) {
430
- _context2.next = 22;
496
+ _context2.next = 30;
431
497
  break;
432
498
  }
433
499
 
434
500
  _Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
435
501
  _iterator = (0, _createForOfIteratorHelperLoose2.default)(methods);
436
502
 
437
- case 9:
503
+ case 10:
438
504
  if ((_step = _iterator()).done) {
439
- _context2.next = 19;
505
+ _context2.next = 27;
440
506
  break;
441
507
  }
442
508
 
@@ -444,42 +510,52 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
444
510
  operation = pathItem[method];
445
511
 
446
512
  if (operation) {
447
- _context2.next = 14;
513
+ _context2.next = 15;
448
514
  break;
449
515
  }
450
516
 
451
- return _context2.abrupt("continue", 17);
517
+ return _context2.abrupt("continue", 25);
452
518
 
453
- case 14:
454
- operationTags = operation.tags || [];
519
+ case 15:
520
+ // 获取接口的目录信息:优先使用 x-apifox-folder
521
+ xApifoxFolder = this.getOperationFolder(operation);
522
+ tagId = this.getTagId(xApifoxFolder);
455
523
 
456
- if (operationTags.length === 0) {
457
- operationTags.push('default');
524
+ if (!(tagId === catId)) {
525
+ _context2.next = 25;
526
+ break;
458
527
  }
459
528
 
460
- for (_iterator2 = (0, _createForOfIteratorHelperLoose2.default)(operationTags); !(_step2 = _iterator2()).done;) {
461
- tag = _step2.value;
462
- tagId = this.getTagId(tag);
529
+ // 去重:基于 path + method
530
+ key = method.toUpperCase() + ":" + path;
463
531
 
464
- if (tagId === catId) {
465
- interfaceInfo = this.convertOperationToInterface(path, method, operation, tag, catId);
466
- interfaces.push(interfaceInfo);
467
- }
532
+ if (!seenKeys.has(key)) {
533
+ _context2.next = 21;
534
+ break;
468
535
  }
469
536
 
470
- case 17:
471
- _context2.next = 9;
537
+ return _context2.abrupt("continue", 25);
538
+
539
+ case 21:
540
+ seenKeys.add(key); // 根据实际的目录名称来确定分类
541
+
542
+ categoryTag = xApifoxFolder;
543
+ interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
544
+ interfaces.push(interfaceInfo);
545
+
546
+ case 25:
547
+ _context2.next = 10;
472
548
  break;
473
549
 
474
- case 19:
550
+ case 27:
475
551
  _i3++;
476
- _context2.next = 6;
552
+ _context2.next = 7;
477
553
  break;
478
554
 
479
- case 22:
555
+ case 30:
480
556
  return _context2.abrupt("return", interfaces);
481
557
 
482
- case 23:
558
+ case 31:
483
559
  case "end":
484
560
  return _context2.stop();
485
561
  }
package/lib/cjs/types.js CHANGED
@@ -52,6 +52,7 @@ exports.RequestParamType = RequestParamType;
52
52
  (function (RequestParamType) {
53
53
  RequestParamType["string"] = "string";
54
54
  RequestParamType["number"] = "number";
55
+ RequestParamType["boolean"] = "boolean";
55
56
  })(RequestParamType || (exports.RequestParamType = RequestParamType = {}));
56
57
 
57
58
  var RequestQueryType;
@@ -62,6 +63,7 @@ exports.RequestQueryType = RequestQueryType;
62
63
  (function (RequestQueryType) {
63
64
  RequestQueryType["string"] = "string";
64
65
  RequestQueryType["number"] = "number";
66
+ RequestQueryType["boolean"] = "boolean";
65
67
  })(RequestQueryType || (exports.RequestQueryType = RequestQueryType = {}));
66
68
 
67
69
  var RequestFormItemType;
@@ -54,6 +54,20 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
54
54
  return resolved.type || 'string';
55
55
  };
56
56
 
57
+ _proto.getRequestParamType = function getRequestParamType(schema) {
58
+ var schemaType = this.getSchemaType(schema);
59
+ if (schemaType === 'boolean') return RequestParamType.boolean;
60
+ if (schemaType === 'number') return RequestParamType.number;
61
+ return RequestParamType.string;
62
+ };
63
+
64
+ _proto.getRequestQueryType = function getRequestQueryType(schema) {
65
+ var schemaType = this.getSchemaType(schema);
66
+ if (schemaType === 'boolean') return RequestQueryType.boolean;
67
+ if (schemaType === 'number') return RequestQueryType.number;
68
+ return RequestQueryType.string;
69
+ };
70
+
57
71
  _proto.convertParametersToReqParams = function convertParametersToReqParams(parameters, type) {
58
72
  var _this = this;
59
73
 
@@ -70,7 +84,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
70
84
  desc: p.description || '',
71
85
  example: p.example || '',
72
86
  required: p.required ? Required.true : Required.false,
73
- type: _this.getSchemaType(p.schema) === 'string' ? RequestParamType.string : RequestParamType.number
87
+ type: _this.getRequestParamType(p.schema)
74
88
  };
75
89
  });
76
90
  }
@@ -83,7 +97,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
83
97
  desc: p.description || '',
84
98
  example: p.example || '',
85
99
  required: p.required ? Required.true : Required.false,
86
- type: _this.getSchemaType(p.schema) === 'string' ? RequestQueryType.string : RequestQueryType.number
100
+ type: _this.getRequestQueryType(p.schema)
87
101
  };
88
102
  });
89
103
  };
@@ -227,9 +241,30 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
227
241
  _proto.generateInterfaceId = function generateInterfaceId() {
228
242
  this.interfaceIdCounter += 1;
229
243
  return this.interfaceIdCounter;
244
+ }
245
+ /**
246
+ * 获取接口所属的目录名称
247
+ * Apifox 优先使用 x-apifox-folder 字段,其次才用 tags[0]
248
+ */
249
+ ;
250
+
251
+ _proto.getOperationFolder = function getOperationFolder(operation) {
252
+ // 优先使用 x-apifox-folder
253
+ if (operation['x-apifox-folder']) {
254
+ return operation['x-apifox-folder'];
255
+ } // 其次使用 tags[0]
256
+
257
+
258
+ if (operation.tags && operation.tags.length > 0) {
259
+ return operation.tags[0];
260
+ }
261
+
262
+ return 'default';
230
263
  };
231
264
 
232
265
  _proto.convertOperationToInterface = function convertOperationToInterface(path, method, operation, categoryName, categoryId) {
266
+ var _operation$tags;
267
+
233
268
  var parameters = operation.parameters || [];
234
269
  var pathParams = this.convertParametersToReqParams(parameters, 'path');
235
270
  var queryParams = this.convertParametersToReqParams(parameters, 'query'); // const headerParams = parameters.filter(p => p.in === 'header')
@@ -247,7 +282,10 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
247
282
  });
248
283
  }
249
284
 
250
- var responseInfo = this.convertResponse(operation.responses);
285
+ var responseInfo = this.convertResponse(operation.responses); // 获取接口所属目录:优先使用 x-apifox-folder,其次用 tags
286
+
287
+ var folderName = this.getOperationFolder(operation);
288
+ var interfaceTags = (_operation$tags = operation.tags) != null && _operation$tags.length ? operation.tags : folderName !== 'default' ? [folderName] : [];
251
289
  return {
252
290
  _id: this.generateInterfaceId(),
253
291
  _category: {
@@ -267,7 +305,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
267
305
  method: method.toUpperCase(),
268
306
  project_id: this.options.projectId,
269
307
  catid: categoryId,
270
- tag: operation.tags || [],
308
+ tag: interfaceTags,
271
309
  req_headers: reqHeaders,
272
310
  req_params: pathParams,
273
311
  req_query: queryParams,
@@ -301,7 +339,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
301
339
  excludedByTags: []
302
340
  },
303
341
  options: {
304
- includeApifoxExtensionProperties: false,
342
+ includeApifoxExtensionProperties: true,
305
343
  addFoldersToTags: (_this$options$addFold = this.options.addFoldersToTags) != null ? _this$options$addFold : true
306
344
  },
307
345
  oasVersion: (_this$options$oasVers = this.options.oasVersion) != null ? _this$options$oasVers : '3.0',
@@ -364,6 +402,25 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
364
402
  }
365
403
 
366
404
  return Math.abs(hash);
405
+ }
406
+ /**
407
+ * 从 OpenAPI tags 中获取目录对应的 tag
408
+ * 如果 x-apifox-folder 在 tags 中存在,则返回对应的 tag;否则返回 x-apifox-folder 本身
409
+ */
410
+ ;
411
+
412
+ _proto.getMatchingTag = function getMatchingTag(xApifoxFolder) {
413
+ var _this$openApiDoc4;
414
+
415
+ if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return null; // 先精确匹配
416
+
417
+ var exactMatch = this.openApiDoc.tags.find(function (tag) {
418
+ return tag.name === xApifoxFolder;
419
+ });
420
+ if (exactMatch) return exactMatch.name; // 如果 addFoldersToTags=true,可能目录名被添加到 tag 描述或其他地方
421
+ // 或者 tag.name 本身就包含了目录路径
422
+
423
+ return null;
367
424
  };
368
425
 
369
426
  _proto.getCats = function getCats(cats) {
@@ -372,12 +429,16 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
372
429
  var categoryIds = getFilteredCat(cats, [], true);
373
430
 
374
431
  if (categoryIds.length === 0 || categoryIds.includes(0)) {
375
- var _this$openApiDoc4;
432
+ var _this$openApiDoc5;
376
433
 
377
- if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return [];
378
- return this.openApiDoc.tags.map(function (tag) {
434
+ if (!((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.tags)) {
435
+ return [];
436
+ }
437
+
438
+ var tagIds = this.openApiDoc.tags.map(function (tag) {
379
439
  return _this2.getTagId(tag.name);
380
440
  });
441
+ return tagIds;
381
442
  }
382
443
 
383
444
  return categoryIds;
@@ -385,15 +446,15 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
385
446
 
386
447
  _proto.getInterfaceList = /*#__PURE__*/function () {
387
448
  var _getInterfaceList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syntheticalConfig) {
388
- var _this$openApiDoc5;
449
+ var _this$openApiDoc6;
389
450
 
390
- var catId, interfaces, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, operationTags, _iterator2, _step2, tag, tagId, interfaceInfo;
451
+ var catId, interfaces, seenKeys, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
391
452
 
392
453
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
393
454
  while (1) {
394
455
  switch (_context2.prev = _context2.next) {
395
456
  case 0:
396
- if ((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.paths) {
457
+ if ((_this$openApiDoc6 = this.openApiDoc) != null && _this$openApiDoc6.paths) {
397
458
  _context2.next = 2;
398
459
  break;
399
460
  }
@@ -402,27 +463,32 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
402
463
 
403
464
  case 2:
404
465
  catId = syntheticalConfig.id;
405
- interfaces = []; // let categoryName = ''
406
- // if (this.openApiDoc.tags) {
407
- // const tag = this.openApiDoc.tags.find(t => this.getTagId(t.name) === catId)
408
- // categoryName = tag?.name || ''
466
+ interfaces = []; // 用于去重:基于 path + method
467
+
468
+ seenKeys = new Set(); // 调试:获取 tag 名称
469
+ // let tagName = 'unknown'
470
+ // if (this.openApiDoc?.tags) {
471
+ // const tag = this.openApiDoc.tags.find(
472
+ // t => this.getTagId(t.name) === catId,
473
+ // )
474
+ // tagName = tag?.name || `unknown(${catId})`
409
475
  // }
410
476
 
411
477
  methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
412
478
  _i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
413
479
 
414
- case 6:
480
+ case 7:
415
481
  if (!(_i3 < _Object$entries3.length)) {
416
- _context2.next = 22;
482
+ _context2.next = 30;
417
483
  break;
418
484
  }
419
485
 
420
486
  _Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
421
487
  _iterator = _createForOfIteratorHelperLoose(methods);
422
488
 
423
- case 9:
489
+ case 10:
424
490
  if ((_step = _iterator()).done) {
425
- _context2.next = 19;
491
+ _context2.next = 27;
426
492
  break;
427
493
  }
428
494
 
@@ -430,42 +496,52 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
430
496
  operation = pathItem[method];
431
497
 
432
498
  if (operation) {
433
- _context2.next = 14;
499
+ _context2.next = 15;
434
500
  break;
435
501
  }
436
502
 
437
- return _context2.abrupt("continue", 17);
503
+ return _context2.abrupt("continue", 25);
438
504
 
439
- case 14:
440
- operationTags = operation.tags || [];
505
+ case 15:
506
+ // 获取接口的目录信息:优先使用 x-apifox-folder
507
+ xApifoxFolder = this.getOperationFolder(operation);
508
+ tagId = this.getTagId(xApifoxFolder);
441
509
 
442
- if (operationTags.length === 0) {
443
- operationTags.push('default');
510
+ if (!(tagId === catId)) {
511
+ _context2.next = 25;
512
+ break;
444
513
  }
445
514
 
446
- for (_iterator2 = _createForOfIteratorHelperLoose(operationTags); !(_step2 = _iterator2()).done;) {
447
- tag = _step2.value;
448
- tagId = this.getTagId(tag);
515
+ // 去重:基于 path + method
516
+ key = method.toUpperCase() + ":" + path;
449
517
 
450
- if (tagId === catId) {
451
- interfaceInfo = this.convertOperationToInterface(path, method, operation, tag, catId);
452
- interfaces.push(interfaceInfo);
453
- }
518
+ if (!seenKeys.has(key)) {
519
+ _context2.next = 21;
520
+ break;
454
521
  }
455
522
 
456
- case 17:
457
- _context2.next = 9;
523
+ return _context2.abrupt("continue", 25);
524
+
525
+ case 21:
526
+ seenKeys.add(key); // 根据实际的目录名称来确定分类
527
+
528
+ categoryTag = xApifoxFolder;
529
+ interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
530
+ interfaces.push(interfaceInfo);
531
+
532
+ case 25:
533
+ _context2.next = 10;
458
534
  break;
459
535
 
460
- case 19:
536
+ case 27:
461
537
  _i3++;
462
- _context2.next = 6;
538
+ _context2.next = 7;
463
539
  break;
464
540
 
465
- case 22:
541
+ case 30:
466
542
  return _context2.abrupt("return", interfaces);
467
543
 
468
- case 23:
544
+ case 31:
469
545
  case "end":
470
546
  return _context2.stop();
471
547
  }
@@ -666,7 +666,9 @@ export declare enum RequestParamType {
666
666
  /** 字符串 */
667
667
  string = "string",
668
668
  /** 数字 */
669
- number = "number"
669
+ number = "number",
670
+ /** 布尔值 */
671
+ boolean = "boolean"
670
672
  }
671
673
 
672
674
  /** 请求查询参数类型 */
@@ -674,7 +676,9 @@ export declare enum RequestQueryType {
674
676
  /** 字符串 */
675
677
  string = "string",
676
678
  /** 数字 */
677
- number = "number"
679
+ number = "number",
680
+ /** 布尔值 */
681
+ boolean = "boolean"
678
682
  }
679
683
 
680
684
  /** 是否必需 */
package/lib/esm/types.js CHANGED
@@ -39,6 +39,7 @@ export var RequestParamType;
39
39
  (function (RequestParamType) {
40
40
  RequestParamType["string"] = "string";
41
41
  RequestParamType["number"] = "number";
42
+ RequestParamType["boolean"] = "boolean";
42
43
  })(RequestParamType || (RequestParamType = {}));
43
44
 
44
45
  export var RequestQueryType;
@@ -47,6 +48,7 @@ export var RequestQueryType;
47
48
  (function (RequestQueryType) {
48
49
  RequestQueryType["string"] = "string";
49
50
  RequestQueryType["number"] = "number";
51
+ RequestQueryType["boolean"] = "boolean";
50
52
  })(RequestQueryType || (RequestQueryType = {}));
51
53
 
52
54
  export var RequestFormItemType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yapi-apifox-to-typescript",
3
- "version": "4.2.0",
3
+ "version": "4.2.2",
4
4
  "description": "根据 YApi 或 Apifox 的接口定义生成 TypeScript/JavaScript 的接口类型及其请求函数代码。",
5
5
  "keywords": [
6
6
  "yapi",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "author": {
21
- "name": "Robin",
22
- "email": "liubingwei318@gmail.com",
21
+ "name": "binwei",
22
+ "email": "462387164@qq.com",
23
23
  "url": "https://github.com/kekexunxun"
24
24
  },
25
25
  "sideEffects": false,
package/CHANGELOG.md DELETED
@@ -1,47 +0,0 @@
1
- # 更新日志
2
-
3
- ## [4.2.0](https://github.com/kekexunxun/yapi-to-typescript/compare/v4.1.3...v4.2.0) (2026-03-16)
4
-
5
- ### [4.1.3](https://github.com/kekexunxun/yapi-to-typescript/compare/v4.1.2...v4.1.3) (2024-12-31)
6
-
7
- ### 修复
8
-
9
- - apifox 接口目录过滤异常的问题 ([2e44000](https://github.com/kekexunxun/yapi-to-typescript/commit/2e44000fc985e825429933c4a569c91b42ba8b21))
10
-
11
- ### [4.1.2](https://github.com/kekexunxun/yapi-to-typescript/compare/v4.1.1...v4.1.2) (2024-12-30)
12
-
13
- ### 修复
14
-
15
- - 调整 ignoreUselessConfigVar 过滤字段 ([7f7eca9](https://github.com/kekexunxun/yapi-to-typescript/commit/7f7eca9be8e32b88a69d12a372b661e3d2b8a4e8))
16
- - apifox 目录过滤失效 ([13b3168](https://github.com/kekexunxun/yapi-to-typescript/commit/13b31689daaa95fab87642f798ff6209e93f5d32))
17
-
18
- ### [4.1.1](https://github.com/kekexunxun/yapi-to-typescript/compare/v4.1.0...v4.1.1) (2024-12-30)
19
-
20
- ### 修复
21
-
22
- - 保留 content-type 的 header 导出 ([7810439](https://github.com/kekexunxun/yapi-to-typescript/commit/7810439f126cff015150664609f72c3733474709))
23
- - 调整构建命令 ([1bfa2b8](https://github.com/kekexunxun/yapi-to-typescript/commit/1bfa2b82dccdb0c597df184f808a24e95bc2c25a))
24
- - 修复入参为 formdata 时,接口定义无数据的问题 ([a60be84](https://github.com/kekexunxun/yapi-to-typescript/commit/a60be847d283dec6417929aaa805d356cba967db))
25
-
26
- ## [4.1.0](https://github.com/kekexunxun/yapi-to-typescript/compare/v4.0.0...v4.1.0) (2024-12-26)
27
-
28
- ### 修复
29
-
30
- - ignoreUselessConfigVar generate error ([5ba5880](https://github.com/kekexunxun/yapi-to-typescript/commit/5ba5880624c1f74332f8b343cda234ef2acf96dd))
31
-
32
- ### 特性
33
-
34
- - 支持多层级的 apifox 接口数据 ([f076d26](https://github.com/kekexunxun/yapi-to-typescript/commit/f076d26546a04c36241c572133e3340b89201ba3))
35
-
36
- ## [4.0.0](https://github.com/kekexunxun/yapi-to-typescript/compare/v3.38.0...v4.0.0) (2024-12-05)
37
-
38
- ### 特性
39
-
40
- - 支持基于 apifox 生成 ([83b6b97](https://github.com/kekexunxun/yapi-to-typescript/commit/83b6b9738cfef282b3684bd98ecd8e841f57f8a3))
41
-
42
- ### 修复
43
-
44
- - 移除其他无用文件 ([8738d3f](https://github.com/kekexunxun/yapi-to-typescript/commit/8738d3fa3521e1fef5617326eda7e7bf4c2f339e))
45
- - apifox 类型定义 ([371a965](https://github.com/kekexunxun/yapi-to-typescript/commit/371a9654191b10f90a4539086ebec4bed02b6656))
46
-
47
- # 更新日志