yapi-apifox-to-typescript 4.2.0 → 4.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/ApifoxToYApiData.js +111 -37
- package/lib/esm/ApifoxToYApiData.js +111 -37
- package/package.json +3 -3
- package/CHANGELOG.md +0 -47
|
@@ -241,9 +241,30 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
241
241
|
_proto.generateInterfaceId = function generateInterfaceId() {
|
|
242
242
|
this.interfaceIdCounter += 1;
|
|
243
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';
|
|
244
263
|
};
|
|
245
264
|
|
|
246
265
|
_proto.convertOperationToInterface = function convertOperationToInterface(path, method, operation, categoryName, categoryId) {
|
|
266
|
+
var _operation$tags;
|
|
267
|
+
|
|
247
268
|
var parameters = operation.parameters || [];
|
|
248
269
|
var pathParams = this.convertParametersToReqParams(parameters, 'path');
|
|
249
270
|
var queryParams = this.convertParametersToReqParams(parameters, 'query'); // const headerParams = parameters.filter(p => p.in === 'header')
|
|
@@ -261,7 +282,10 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
261
282
|
});
|
|
262
283
|
}
|
|
263
284
|
|
|
264
|
-
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] : [];
|
|
265
289
|
return {
|
|
266
290
|
_id: this.generateInterfaceId(),
|
|
267
291
|
_category: {
|
|
@@ -281,7 +305,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
281
305
|
method: method.toUpperCase(),
|
|
282
306
|
project_id: this.options.projectId,
|
|
283
307
|
catid: categoryId,
|
|
284
|
-
tag:
|
|
308
|
+
tag: interfaceTags,
|
|
285
309
|
req_headers: reqHeaders,
|
|
286
310
|
req_params: pathParams,
|
|
287
311
|
req_query: queryParams,
|
|
@@ -315,7 +339,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
315
339
|
excludedByTags: []
|
|
316
340
|
},
|
|
317
341
|
options: {
|
|
318
|
-
includeApifoxExtensionProperties:
|
|
342
|
+
includeApifoxExtensionProperties: true,
|
|
319
343
|
addFoldersToTags: (_this$options$addFold = this.options.addFoldersToTags) != null ? _this$options$addFold : true
|
|
320
344
|
},
|
|
321
345
|
oasVersion: (_this$options$oasVers = this.options.oasVersion) != null ? _this$options$oasVers : '3.0',
|
|
@@ -378,6 +402,25 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
378
402
|
}
|
|
379
403
|
|
|
380
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;
|
|
381
424
|
};
|
|
382
425
|
|
|
383
426
|
_proto.getCats = function getCats(cats) {
|
|
@@ -386,28 +429,40 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
386
429
|
var categoryIds = (0, _utils.getFilteredCat)(cats, [], true);
|
|
387
430
|
|
|
388
431
|
if (categoryIds.length === 0 || categoryIds.includes(0)) {
|
|
389
|
-
var _this$
|
|
432
|
+
var _this$openApiDoc5;
|
|
390
433
|
|
|
391
|
-
if (!((_this$
|
|
392
|
-
|
|
434
|
+
if (!((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.tags)) {
|
|
435
|
+
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE\u7A7A\u6570\u7EC4 (openApiDoc.tags \u4E0D\u5B58\u5728)");
|
|
436
|
+
return [];
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
var tagIds = this.openApiDoc.tags.map(function (tag) {
|
|
393
440
|
return _this2.getTagId(tag.name);
|
|
394
441
|
});
|
|
442
|
+
console.log("\uD83D\uDCC1 getCats (id=0 \u83B7\u53D6\u5168\u90E8): \u8FD4\u56DE " + tagIds.length + " \u4E2A\u5206\u7C7B");
|
|
443
|
+
console.log(" Tags: " + this.openApiDoc.tags.map(function (t) {
|
|
444
|
+
return t.name;
|
|
445
|
+
}).join(', '));
|
|
446
|
+
return tagIds;
|
|
395
447
|
}
|
|
396
448
|
|
|
449
|
+
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE " + categoryIds.length + " \u4E2A\u5206\u7C7B: " + categoryIds.join(', '));
|
|
397
450
|
return categoryIds;
|
|
398
451
|
};
|
|
399
452
|
|
|
400
453
|
_proto.getInterfaceList = /*#__PURE__*/function () {
|
|
401
454
|
var _getInterfaceList = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syntheticalConfig) {
|
|
402
|
-
var _this$
|
|
455
|
+
var _this$openApiDoc6,
|
|
456
|
+
_this$openApiDoc7,
|
|
457
|
+
_this3 = this;
|
|
403
458
|
|
|
404
|
-
var catId, interfaces, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation,
|
|
459
|
+
var catId, interfaces, seenKeys, tagName, tag, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
|
|
405
460
|
|
|
406
461
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
407
462
|
while (1) {
|
|
408
463
|
switch (_context2.prev = _context2.next) {
|
|
409
464
|
case 0:
|
|
410
|
-
if ((_this$
|
|
465
|
+
if ((_this$openApiDoc6 = this.openApiDoc) != null && _this$openApiDoc6.paths) {
|
|
411
466
|
_context2.next = 2;
|
|
412
467
|
break;
|
|
413
468
|
}
|
|
@@ -416,27 +471,35 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
416
471
|
|
|
417
472
|
case 2:
|
|
418
473
|
catId = syntheticalConfig.id;
|
|
419
|
-
interfaces = []; //
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
474
|
+
interfaces = []; // 用于去重:基于 path + method
|
|
475
|
+
|
|
476
|
+
seenKeys = new Set(); // 调试:获取 tag 名称
|
|
477
|
+
|
|
478
|
+
tagName = 'unknown';
|
|
479
|
+
|
|
480
|
+
if ((_this$openApiDoc7 = this.openApiDoc) != null && _this$openApiDoc7.tags) {
|
|
481
|
+
tag = this.openApiDoc.tags.find(function (t) {
|
|
482
|
+
return _this3.getTagId(t.name) === catId;
|
|
483
|
+
});
|
|
484
|
+
tagName = (tag == null ? void 0 : tag.name) || "unknown(" + catId + ")";
|
|
485
|
+
}
|
|
424
486
|
|
|
487
|
+
console.log("\n\uD83D\uDCC2 \u5206\u7C7B [" + tagName + "] (id: " + catId + ") \u5F00\u59CB\u83B7\u53D6\u63A5\u53E3...");
|
|
425
488
|
methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
426
489
|
_i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
|
|
427
490
|
|
|
428
|
-
case
|
|
491
|
+
case 10:
|
|
429
492
|
if (!(_i3 < _Object$entries3.length)) {
|
|
430
|
-
_context2.next =
|
|
493
|
+
_context2.next = 34;
|
|
431
494
|
break;
|
|
432
495
|
}
|
|
433
496
|
|
|
434
497
|
_Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
|
|
435
498
|
_iterator = (0, _createForOfIteratorHelperLoose2.default)(methods);
|
|
436
499
|
|
|
437
|
-
case
|
|
500
|
+
case 13:
|
|
438
501
|
if ((_step = _iterator()).done) {
|
|
439
|
-
_context2.next =
|
|
502
|
+
_context2.next = 31;
|
|
440
503
|
break;
|
|
441
504
|
}
|
|
442
505
|
|
|
@@ -444,42 +507,53 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
444
507
|
operation = pathItem[method];
|
|
445
508
|
|
|
446
509
|
if (operation) {
|
|
447
|
-
_context2.next =
|
|
510
|
+
_context2.next = 18;
|
|
448
511
|
break;
|
|
449
512
|
}
|
|
450
513
|
|
|
451
|
-
return _context2.abrupt("continue",
|
|
514
|
+
return _context2.abrupt("continue", 29);
|
|
452
515
|
|
|
453
|
-
case
|
|
454
|
-
|
|
516
|
+
case 18:
|
|
517
|
+
// 获取接口的目录信息:优先使用 x-apifox-folder
|
|
518
|
+
xApifoxFolder = this.getOperationFolder(operation);
|
|
519
|
+
tagId = this.getTagId(xApifoxFolder);
|
|
455
520
|
|
|
456
|
-
if (
|
|
457
|
-
|
|
521
|
+
if (!(tagId === catId)) {
|
|
522
|
+
_context2.next = 29;
|
|
523
|
+
break;
|
|
458
524
|
}
|
|
459
525
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
tagId = this.getTagId(tag);
|
|
526
|
+
// 去重:基于 path + method
|
|
527
|
+
key = method.toUpperCase() + ":" + path;
|
|
463
528
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
}
|
|
529
|
+
if (!seenKeys.has(key)) {
|
|
530
|
+
_context2.next = 25;
|
|
531
|
+
break;
|
|
468
532
|
}
|
|
469
533
|
|
|
470
|
-
|
|
471
|
-
_context2.
|
|
534
|
+
console.log(" \u26A0\uFE0F \u8DF3\u8FC7\u91CD\u590D\u63A5\u53E3: " + key);
|
|
535
|
+
return _context2.abrupt("continue", 29);
|
|
536
|
+
|
|
537
|
+
case 25:
|
|
538
|
+
seenKeys.add(key); // 根据实际的目录名称来确定分类
|
|
539
|
+
|
|
540
|
+
categoryTag = xApifoxFolder;
|
|
541
|
+
interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
|
|
542
|
+
interfaces.push(interfaceInfo);
|
|
543
|
+
|
|
544
|
+
case 29:
|
|
545
|
+
_context2.next = 13;
|
|
472
546
|
break;
|
|
473
547
|
|
|
474
|
-
case
|
|
548
|
+
case 31:
|
|
475
549
|
_i3++;
|
|
476
|
-
_context2.next =
|
|
550
|
+
_context2.next = 10;
|
|
477
551
|
break;
|
|
478
552
|
|
|
479
|
-
case
|
|
553
|
+
case 34:
|
|
480
554
|
return _context2.abrupt("return", interfaces);
|
|
481
555
|
|
|
482
|
-
case
|
|
556
|
+
case 35:
|
|
483
557
|
case "end":
|
|
484
558
|
return _context2.stop();
|
|
485
559
|
}
|
|
@@ -227,9 +227,30 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
227
227
|
_proto.generateInterfaceId = function generateInterfaceId() {
|
|
228
228
|
this.interfaceIdCounter += 1;
|
|
229
229
|
return this.interfaceIdCounter;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 获取接口所属的目录名称
|
|
233
|
+
* Apifox 优先使用 x-apifox-folder 字段,其次才用 tags[0]
|
|
234
|
+
*/
|
|
235
|
+
;
|
|
236
|
+
|
|
237
|
+
_proto.getOperationFolder = function getOperationFolder(operation) {
|
|
238
|
+
// 优先使用 x-apifox-folder
|
|
239
|
+
if (operation['x-apifox-folder']) {
|
|
240
|
+
return operation['x-apifox-folder'];
|
|
241
|
+
} // 其次使用 tags[0]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
if (operation.tags && operation.tags.length > 0) {
|
|
245
|
+
return operation.tags[0];
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return 'default';
|
|
230
249
|
};
|
|
231
250
|
|
|
232
251
|
_proto.convertOperationToInterface = function convertOperationToInterface(path, method, operation, categoryName, categoryId) {
|
|
252
|
+
var _operation$tags;
|
|
253
|
+
|
|
233
254
|
var parameters = operation.parameters || [];
|
|
234
255
|
var pathParams = this.convertParametersToReqParams(parameters, 'path');
|
|
235
256
|
var queryParams = this.convertParametersToReqParams(parameters, 'query'); // const headerParams = parameters.filter(p => p.in === 'header')
|
|
@@ -247,7 +268,10 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
247
268
|
});
|
|
248
269
|
}
|
|
249
270
|
|
|
250
|
-
var responseInfo = this.convertResponse(operation.responses);
|
|
271
|
+
var responseInfo = this.convertResponse(operation.responses); // 获取接口所属目录:优先使用 x-apifox-folder,其次用 tags
|
|
272
|
+
|
|
273
|
+
var folderName = this.getOperationFolder(operation);
|
|
274
|
+
var interfaceTags = (_operation$tags = operation.tags) != null && _operation$tags.length ? operation.tags : folderName !== 'default' ? [folderName] : [];
|
|
251
275
|
return {
|
|
252
276
|
_id: this.generateInterfaceId(),
|
|
253
277
|
_category: {
|
|
@@ -267,7 +291,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
267
291
|
method: method.toUpperCase(),
|
|
268
292
|
project_id: this.options.projectId,
|
|
269
293
|
catid: categoryId,
|
|
270
|
-
tag:
|
|
294
|
+
tag: interfaceTags,
|
|
271
295
|
req_headers: reqHeaders,
|
|
272
296
|
req_params: pathParams,
|
|
273
297
|
req_query: queryParams,
|
|
@@ -301,7 +325,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
301
325
|
excludedByTags: []
|
|
302
326
|
},
|
|
303
327
|
options: {
|
|
304
|
-
includeApifoxExtensionProperties:
|
|
328
|
+
includeApifoxExtensionProperties: true,
|
|
305
329
|
addFoldersToTags: (_this$options$addFold = this.options.addFoldersToTags) != null ? _this$options$addFold : true
|
|
306
330
|
},
|
|
307
331
|
oasVersion: (_this$options$oasVers = this.options.oasVersion) != null ? _this$options$oasVers : '3.0',
|
|
@@ -364,6 +388,25 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
364
388
|
}
|
|
365
389
|
|
|
366
390
|
return Math.abs(hash);
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* 从 OpenAPI tags 中获取目录对应的 tag
|
|
394
|
+
* 如果 x-apifox-folder 在 tags 中存在,则返回对应的 tag;否则返回 x-apifox-folder 本身
|
|
395
|
+
*/
|
|
396
|
+
;
|
|
397
|
+
|
|
398
|
+
_proto.getMatchingTag = function getMatchingTag(xApifoxFolder) {
|
|
399
|
+
var _this$openApiDoc4;
|
|
400
|
+
|
|
401
|
+
if (!((_this$openApiDoc4 = this.openApiDoc) != null && _this$openApiDoc4.tags)) return null; // 先精确匹配
|
|
402
|
+
|
|
403
|
+
var exactMatch = this.openApiDoc.tags.find(function (tag) {
|
|
404
|
+
return tag.name === xApifoxFolder;
|
|
405
|
+
});
|
|
406
|
+
if (exactMatch) return exactMatch.name; // 如果 addFoldersToTags=true,可能目录名被添加到 tag 描述或其他地方
|
|
407
|
+
// 或者 tag.name 本身就包含了目录路径
|
|
408
|
+
|
|
409
|
+
return null;
|
|
367
410
|
};
|
|
368
411
|
|
|
369
412
|
_proto.getCats = function getCats(cats) {
|
|
@@ -372,28 +415,40 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
372
415
|
var categoryIds = getFilteredCat(cats, [], true);
|
|
373
416
|
|
|
374
417
|
if (categoryIds.length === 0 || categoryIds.includes(0)) {
|
|
375
|
-
var _this$
|
|
418
|
+
var _this$openApiDoc5;
|
|
376
419
|
|
|
377
|
-
if (!((_this$
|
|
378
|
-
|
|
420
|
+
if (!((_this$openApiDoc5 = this.openApiDoc) != null && _this$openApiDoc5.tags)) {
|
|
421
|
+
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE\u7A7A\u6570\u7EC4 (openApiDoc.tags \u4E0D\u5B58\u5728)");
|
|
422
|
+
return [];
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
var tagIds = this.openApiDoc.tags.map(function (tag) {
|
|
379
426
|
return _this2.getTagId(tag.name);
|
|
380
427
|
});
|
|
428
|
+
console.log("\uD83D\uDCC1 getCats (id=0 \u83B7\u53D6\u5168\u90E8): \u8FD4\u56DE " + tagIds.length + " \u4E2A\u5206\u7C7B");
|
|
429
|
+
console.log(" Tags: " + this.openApiDoc.tags.map(function (t) {
|
|
430
|
+
return t.name;
|
|
431
|
+
}).join(', '));
|
|
432
|
+
return tagIds;
|
|
381
433
|
}
|
|
382
434
|
|
|
435
|
+
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE " + categoryIds.length + " \u4E2A\u5206\u7C7B: " + categoryIds.join(', '));
|
|
383
436
|
return categoryIds;
|
|
384
437
|
};
|
|
385
438
|
|
|
386
439
|
_proto.getInterfaceList = /*#__PURE__*/function () {
|
|
387
440
|
var _getInterfaceList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syntheticalConfig) {
|
|
388
|
-
var _this$
|
|
441
|
+
var _this$openApiDoc6,
|
|
442
|
+
_this$openApiDoc7,
|
|
443
|
+
_this3 = this;
|
|
389
444
|
|
|
390
|
-
var catId, interfaces, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation,
|
|
445
|
+
var catId, interfaces, seenKeys, tagName, tag, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
|
|
391
446
|
|
|
392
447
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
393
448
|
while (1) {
|
|
394
449
|
switch (_context2.prev = _context2.next) {
|
|
395
450
|
case 0:
|
|
396
|
-
if ((_this$
|
|
451
|
+
if ((_this$openApiDoc6 = this.openApiDoc) != null && _this$openApiDoc6.paths) {
|
|
397
452
|
_context2.next = 2;
|
|
398
453
|
break;
|
|
399
454
|
}
|
|
@@ -402,27 +457,35 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
402
457
|
|
|
403
458
|
case 2:
|
|
404
459
|
catId = syntheticalConfig.id;
|
|
405
|
-
interfaces = []; //
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
460
|
+
interfaces = []; // 用于去重:基于 path + method
|
|
461
|
+
|
|
462
|
+
seenKeys = new Set(); // 调试:获取 tag 名称
|
|
463
|
+
|
|
464
|
+
tagName = 'unknown';
|
|
465
|
+
|
|
466
|
+
if ((_this$openApiDoc7 = this.openApiDoc) != null && _this$openApiDoc7.tags) {
|
|
467
|
+
tag = this.openApiDoc.tags.find(function (t) {
|
|
468
|
+
return _this3.getTagId(t.name) === catId;
|
|
469
|
+
});
|
|
470
|
+
tagName = (tag == null ? void 0 : tag.name) || "unknown(" + catId + ")";
|
|
471
|
+
}
|
|
410
472
|
|
|
473
|
+
console.log("\n\uD83D\uDCC2 \u5206\u7C7B [" + tagName + "] (id: " + catId + ") \u5F00\u59CB\u83B7\u53D6\u63A5\u53E3...");
|
|
411
474
|
methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
412
475
|
_i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
|
|
413
476
|
|
|
414
|
-
case
|
|
477
|
+
case 10:
|
|
415
478
|
if (!(_i3 < _Object$entries3.length)) {
|
|
416
|
-
_context2.next =
|
|
479
|
+
_context2.next = 34;
|
|
417
480
|
break;
|
|
418
481
|
}
|
|
419
482
|
|
|
420
483
|
_Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
|
|
421
484
|
_iterator = _createForOfIteratorHelperLoose(methods);
|
|
422
485
|
|
|
423
|
-
case
|
|
486
|
+
case 13:
|
|
424
487
|
if ((_step = _iterator()).done) {
|
|
425
|
-
_context2.next =
|
|
488
|
+
_context2.next = 31;
|
|
426
489
|
break;
|
|
427
490
|
}
|
|
428
491
|
|
|
@@ -430,42 +493,53 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
430
493
|
operation = pathItem[method];
|
|
431
494
|
|
|
432
495
|
if (operation) {
|
|
433
|
-
_context2.next =
|
|
496
|
+
_context2.next = 18;
|
|
434
497
|
break;
|
|
435
498
|
}
|
|
436
499
|
|
|
437
|
-
return _context2.abrupt("continue",
|
|
500
|
+
return _context2.abrupt("continue", 29);
|
|
438
501
|
|
|
439
|
-
case
|
|
440
|
-
|
|
502
|
+
case 18:
|
|
503
|
+
// 获取接口的目录信息:优先使用 x-apifox-folder
|
|
504
|
+
xApifoxFolder = this.getOperationFolder(operation);
|
|
505
|
+
tagId = this.getTagId(xApifoxFolder);
|
|
441
506
|
|
|
442
|
-
if (
|
|
443
|
-
|
|
507
|
+
if (!(tagId === catId)) {
|
|
508
|
+
_context2.next = 29;
|
|
509
|
+
break;
|
|
444
510
|
}
|
|
445
511
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
tagId = this.getTagId(tag);
|
|
512
|
+
// 去重:基于 path + method
|
|
513
|
+
key = method.toUpperCase() + ":" + path;
|
|
449
514
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
}
|
|
515
|
+
if (!seenKeys.has(key)) {
|
|
516
|
+
_context2.next = 25;
|
|
517
|
+
break;
|
|
454
518
|
}
|
|
455
519
|
|
|
456
|
-
|
|
457
|
-
_context2.
|
|
520
|
+
console.log(" \u26A0\uFE0F \u8DF3\u8FC7\u91CD\u590D\u63A5\u53E3: " + key);
|
|
521
|
+
return _context2.abrupt("continue", 29);
|
|
522
|
+
|
|
523
|
+
case 25:
|
|
524
|
+
seenKeys.add(key); // 根据实际的目录名称来确定分类
|
|
525
|
+
|
|
526
|
+
categoryTag = xApifoxFolder;
|
|
527
|
+
interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
|
|
528
|
+
interfaces.push(interfaceInfo);
|
|
529
|
+
|
|
530
|
+
case 29:
|
|
531
|
+
_context2.next = 13;
|
|
458
532
|
break;
|
|
459
533
|
|
|
460
|
-
case
|
|
534
|
+
case 31:
|
|
461
535
|
_i3++;
|
|
462
|
-
_context2.next =
|
|
536
|
+
_context2.next = 10;
|
|
463
537
|
break;
|
|
464
538
|
|
|
465
|
-
case
|
|
539
|
+
case 34:
|
|
466
540
|
return _context2.abrupt("return", interfaces);
|
|
467
541
|
|
|
468
|
-
case
|
|
542
|
+
case 35:
|
|
469
543
|
case "end":
|
|
470
544
|
return _context2.stop();
|
|
471
545
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yapi-apifox-to-typescript",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.1",
|
|
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": "
|
|
22
|
-
"email": "
|
|
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
|
-
# 更新日志
|