yapi-apifox-to-typescript 4.2.1 → 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.
- package/lib/cjs/ApifoxToYApiData.js +42 -40
- package/lib/cjs/types.js +2 -0
- package/lib/esm/ApifoxToYApiData.js +42 -40
- package/lib/esm/index.d.ts +6 -2
- package/lib/esm/types.js +2 -0
- package/package.json +1 -1
|
@@ -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.
|
|
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.
|
|
114
|
+
type: _this.getRequestQueryType(p.schema)
|
|
101
115
|
};
|
|
102
116
|
});
|
|
103
117
|
};
|
|
@@ -432,31 +446,23 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
432
446
|
var _this$openApiDoc5;
|
|
433
447
|
|
|
434
448
|
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
449
|
return [];
|
|
437
450
|
}
|
|
438
451
|
|
|
439
452
|
var tagIds = this.openApiDoc.tags.map(function (tag) {
|
|
440
453
|
return _this2.getTagId(tag.name);
|
|
441
454
|
});
|
|
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
455
|
return tagIds;
|
|
447
456
|
}
|
|
448
457
|
|
|
449
|
-
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE " + categoryIds.length + " \u4E2A\u5206\u7C7B: " + categoryIds.join(', '));
|
|
450
458
|
return categoryIds;
|
|
451
459
|
};
|
|
452
460
|
|
|
453
461
|
_proto.getInterfaceList = /*#__PURE__*/function () {
|
|
454
462
|
var _getInterfaceList = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(syntheticalConfig) {
|
|
455
|
-
var _this$openApiDoc6
|
|
456
|
-
_this$openApiDoc7,
|
|
457
|
-
_this3 = this;
|
|
463
|
+
var _this$openApiDoc6;
|
|
458
464
|
|
|
459
|
-
var catId, interfaces, seenKeys,
|
|
465
|
+
var catId, interfaces, seenKeys, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
|
|
460
466
|
|
|
461
467
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
462
468
|
while (1) {
|
|
@@ -474,32 +480,29 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
474
480
|
interfaces = []; // 用于去重:基于 path + method
|
|
475
481
|
|
|
476
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})`
|
|
489
|
+
// }
|
|
477
490
|
|
|
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
|
-
}
|
|
486
|
-
|
|
487
|
-
console.log("\n\uD83D\uDCC2 \u5206\u7C7B [" + tagName + "] (id: " + catId + ") \u5F00\u59CB\u83B7\u53D6\u63A5\u53E3...");
|
|
488
491
|
methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
489
492
|
_i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
|
|
490
493
|
|
|
491
|
-
case
|
|
494
|
+
case 7:
|
|
492
495
|
if (!(_i3 < _Object$entries3.length)) {
|
|
493
|
-
_context2.next =
|
|
496
|
+
_context2.next = 30;
|
|
494
497
|
break;
|
|
495
498
|
}
|
|
496
499
|
|
|
497
500
|
_Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
|
|
498
501
|
_iterator = (0, _createForOfIteratorHelperLoose2.default)(methods);
|
|
499
502
|
|
|
500
|
-
case
|
|
503
|
+
case 10:
|
|
501
504
|
if ((_step = _iterator()).done) {
|
|
502
|
-
_context2.next =
|
|
505
|
+
_context2.next = 27;
|
|
503
506
|
break;
|
|
504
507
|
}
|
|
505
508
|
|
|
@@ -507,19 +510,19 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
507
510
|
operation = pathItem[method];
|
|
508
511
|
|
|
509
512
|
if (operation) {
|
|
510
|
-
_context2.next =
|
|
513
|
+
_context2.next = 15;
|
|
511
514
|
break;
|
|
512
515
|
}
|
|
513
516
|
|
|
514
|
-
return _context2.abrupt("continue",
|
|
517
|
+
return _context2.abrupt("continue", 25);
|
|
515
518
|
|
|
516
|
-
case
|
|
519
|
+
case 15:
|
|
517
520
|
// 获取接口的目录信息:优先使用 x-apifox-folder
|
|
518
521
|
xApifoxFolder = this.getOperationFolder(operation);
|
|
519
522
|
tagId = this.getTagId(xApifoxFolder);
|
|
520
523
|
|
|
521
524
|
if (!(tagId === catId)) {
|
|
522
|
-
_context2.next =
|
|
525
|
+
_context2.next = 25;
|
|
523
526
|
break;
|
|
524
527
|
}
|
|
525
528
|
|
|
@@ -527,33 +530,32 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
527
530
|
key = method.toUpperCase() + ":" + path;
|
|
528
531
|
|
|
529
532
|
if (!seenKeys.has(key)) {
|
|
530
|
-
_context2.next =
|
|
533
|
+
_context2.next = 21;
|
|
531
534
|
break;
|
|
532
535
|
}
|
|
533
536
|
|
|
534
|
-
|
|
535
|
-
return _context2.abrupt("continue", 29);
|
|
537
|
+
return _context2.abrupt("continue", 25);
|
|
536
538
|
|
|
537
|
-
case
|
|
539
|
+
case 21:
|
|
538
540
|
seenKeys.add(key); // 根据实际的目录名称来确定分类
|
|
539
541
|
|
|
540
542
|
categoryTag = xApifoxFolder;
|
|
541
543
|
interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
|
|
542
544
|
interfaces.push(interfaceInfo);
|
|
543
545
|
|
|
544
|
-
case
|
|
545
|
-
_context2.next =
|
|
546
|
+
case 25:
|
|
547
|
+
_context2.next = 10;
|
|
546
548
|
break;
|
|
547
549
|
|
|
548
|
-
case
|
|
550
|
+
case 27:
|
|
549
551
|
_i3++;
|
|
550
|
-
_context2.next =
|
|
552
|
+
_context2.next = 7;
|
|
551
553
|
break;
|
|
552
554
|
|
|
553
|
-
case
|
|
555
|
+
case 30:
|
|
554
556
|
return _context2.abrupt("return", interfaces);
|
|
555
557
|
|
|
556
|
-
case
|
|
558
|
+
case 31:
|
|
557
559
|
case "end":
|
|
558
560
|
return _context2.stop();
|
|
559
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.
|
|
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.
|
|
100
|
+
type: _this.getRequestQueryType(p.schema)
|
|
87
101
|
};
|
|
88
102
|
});
|
|
89
103
|
};
|
|
@@ -418,31 +432,23 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
418
432
|
var _this$openApiDoc5;
|
|
419
433
|
|
|
420
434
|
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
435
|
return [];
|
|
423
436
|
}
|
|
424
437
|
|
|
425
438
|
var tagIds = this.openApiDoc.tags.map(function (tag) {
|
|
426
439
|
return _this2.getTagId(tag.name);
|
|
427
440
|
});
|
|
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
441
|
return tagIds;
|
|
433
442
|
}
|
|
434
443
|
|
|
435
|
-
console.log("\uD83D\uDCC1 getCats: \u8FD4\u56DE " + categoryIds.length + " \u4E2A\u5206\u7C7B: " + categoryIds.join(', '));
|
|
436
444
|
return categoryIds;
|
|
437
445
|
};
|
|
438
446
|
|
|
439
447
|
_proto.getInterfaceList = /*#__PURE__*/function () {
|
|
440
448
|
var _getInterfaceList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syntheticalConfig) {
|
|
441
|
-
var _this$openApiDoc6
|
|
442
|
-
_this$openApiDoc7,
|
|
443
|
-
_this3 = this;
|
|
449
|
+
var _this$openApiDoc6;
|
|
444
450
|
|
|
445
|
-
var catId, interfaces, seenKeys,
|
|
451
|
+
var catId, interfaces, seenKeys, methods, _i3, _Object$entries3, _Object$entries3$_i, path, pathItem, _iterator, _step, method, operation, xApifoxFolder, tagId, key, categoryTag, interfaceInfo;
|
|
446
452
|
|
|
447
453
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
448
454
|
while (1) {
|
|
@@ -460,32 +466,29 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
460
466
|
interfaces = []; // 用于去重:基于 path + method
|
|
461
467
|
|
|
462
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})`
|
|
475
|
+
// }
|
|
463
476
|
|
|
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
|
-
}
|
|
472
|
-
|
|
473
|
-
console.log("\n\uD83D\uDCC2 \u5206\u7C7B [" + tagName + "] (id: " + catId + ") \u5F00\u59CB\u83B7\u53D6\u63A5\u53E3...");
|
|
474
477
|
methods = ['get', 'post', 'put', 'delete', 'patch', 'head', 'options'];
|
|
475
478
|
_i3 = 0, _Object$entries3 = Object.entries(this.openApiDoc.paths);
|
|
476
479
|
|
|
477
|
-
case
|
|
480
|
+
case 7:
|
|
478
481
|
if (!(_i3 < _Object$entries3.length)) {
|
|
479
|
-
_context2.next =
|
|
482
|
+
_context2.next = 30;
|
|
480
483
|
break;
|
|
481
484
|
}
|
|
482
485
|
|
|
483
486
|
_Object$entries3$_i = _Object$entries3[_i3], path = _Object$entries3$_i[0], pathItem = _Object$entries3$_i[1];
|
|
484
487
|
_iterator = _createForOfIteratorHelperLoose(methods);
|
|
485
488
|
|
|
486
|
-
case
|
|
489
|
+
case 10:
|
|
487
490
|
if ((_step = _iterator()).done) {
|
|
488
|
-
_context2.next =
|
|
491
|
+
_context2.next = 27;
|
|
489
492
|
break;
|
|
490
493
|
}
|
|
491
494
|
|
|
@@ -493,19 +496,19 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
493
496
|
operation = pathItem[method];
|
|
494
497
|
|
|
495
498
|
if (operation) {
|
|
496
|
-
_context2.next =
|
|
499
|
+
_context2.next = 15;
|
|
497
500
|
break;
|
|
498
501
|
}
|
|
499
502
|
|
|
500
|
-
return _context2.abrupt("continue",
|
|
503
|
+
return _context2.abrupt("continue", 25);
|
|
501
504
|
|
|
502
|
-
case
|
|
505
|
+
case 15:
|
|
503
506
|
// 获取接口的目录信息:优先使用 x-apifox-folder
|
|
504
507
|
xApifoxFolder = this.getOperationFolder(operation);
|
|
505
508
|
tagId = this.getTagId(xApifoxFolder);
|
|
506
509
|
|
|
507
510
|
if (!(tagId === catId)) {
|
|
508
|
-
_context2.next =
|
|
511
|
+
_context2.next = 25;
|
|
509
512
|
break;
|
|
510
513
|
}
|
|
511
514
|
|
|
@@ -513,33 +516,32 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
|
|
|
513
516
|
key = method.toUpperCase() + ":" + path;
|
|
514
517
|
|
|
515
518
|
if (!seenKeys.has(key)) {
|
|
516
|
-
_context2.next =
|
|
519
|
+
_context2.next = 21;
|
|
517
520
|
break;
|
|
518
521
|
}
|
|
519
522
|
|
|
520
|
-
|
|
521
|
-
return _context2.abrupt("continue", 29);
|
|
523
|
+
return _context2.abrupt("continue", 25);
|
|
522
524
|
|
|
523
|
-
case
|
|
525
|
+
case 21:
|
|
524
526
|
seenKeys.add(key); // 根据实际的目录名称来确定分类
|
|
525
527
|
|
|
526
528
|
categoryTag = xApifoxFolder;
|
|
527
529
|
interfaceInfo = this.convertOperationToInterface(path, method, operation, categoryTag, catId);
|
|
528
530
|
interfaces.push(interfaceInfo);
|
|
529
531
|
|
|
530
|
-
case
|
|
531
|
-
_context2.next =
|
|
532
|
+
case 25:
|
|
533
|
+
_context2.next = 10;
|
|
532
534
|
break;
|
|
533
535
|
|
|
534
|
-
case
|
|
536
|
+
case 27:
|
|
535
537
|
_i3++;
|
|
536
|
-
_context2.next =
|
|
538
|
+
_context2.next = 7;
|
|
537
539
|
break;
|
|
538
540
|
|
|
539
|
-
case
|
|
541
|
+
case 30:
|
|
540
542
|
return _context2.abrupt("return", interfaces);
|
|
541
543
|
|
|
542
|
-
case
|
|
544
|
+
case 31:
|
|
543
545
|
case "end":
|
|
544
546
|
return _context2.stop();
|
|
545
547
|
}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -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;
|