@asyncapi/cli 2.5.0 → 2.6.0
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/assets/create-glee-app/templates/default/package-lock.json +3 -3
- package/assets/create-glee-app/templates/tutorial/package-lock.json +3 -3
- package/lib/commands/convert.d.ts +9 -0
- package/lib/commands/convert.js +82 -42
- package/lib/core/flags/convert.flags.js +1 -1
- package/oclif.manifest.json +5 -3
- package/package.json +1 -1
|
@@ -11518,9 +11518,9 @@
|
|
|
11518
11518
|
}
|
|
11519
11519
|
},
|
|
11520
11520
|
"node_modules/rollup": {
|
|
11521
|
-
"version": "2.79.
|
|
11522
|
-
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.
|
|
11523
|
-
"integrity": "sha512-
|
|
11521
|
+
"version": "2.79.2",
|
|
11522
|
+
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz",
|
|
11523
|
+
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
|
11524
11524
|
"bin": {
|
|
11525
11525
|
"rollup": "dist/bin/rollup"
|
|
11526
11526
|
},
|
|
@@ -11515,9 +11515,9 @@
|
|
|
11515
11515
|
}
|
|
11516
11516
|
},
|
|
11517
11517
|
"node_modules/rollup": {
|
|
11518
|
-
"version": "2.79.
|
|
11519
|
-
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.
|
|
11520
|
-
"integrity": "sha512-
|
|
11518
|
+
"version": "2.79.2",
|
|
11519
|
+
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.79.2.tgz",
|
|
11520
|
+
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
|
11521
11521
|
"bin": {
|
|
11522
11522
|
"rollup": "dist/bin/rollup"
|
|
11523
11523
|
},
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Command from '../core/base';
|
|
2
2
|
export default class Convert extends Command {
|
|
3
|
+
static specFile: any;
|
|
4
|
+
static metricsMetadata: any;
|
|
3
5
|
static description: string;
|
|
4
6
|
static flags: {
|
|
5
7
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
@@ -12,4 +14,11 @@ export default class Convert extends Command {
|
|
|
12
14
|
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
15
|
};
|
|
14
16
|
run(): Promise<void>;
|
|
17
|
+
private handleConversion;
|
|
18
|
+
private convertOpenAPI;
|
|
19
|
+
private convertAsyncAPI;
|
|
20
|
+
private convertPostman;
|
|
21
|
+
private formatConvertedFile;
|
|
22
|
+
private handleOutput;
|
|
23
|
+
private handleError;
|
|
15
24
|
}
|
package/lib/commands/convert.js
CHANGED
|
@@ -16,7 +16,6 @@ const convert_flags_1 = require("../core/flags/convert.flags");
|
|
|
16
16
|
const latestVersion = Object.keys(specs_1.default.schemas).pop();
|
|
17
17
|
class Convert extends base_1.default {
|
|
18
18
|
run() {
|
|
19
|
-
var _a;
|
|
20
19
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
20
|
const { args, flags } = yield this.parse(Convert);
|
|
22
21
|
const filePath = args['spec-file'];
|
|
@@ -28,57 +27,98 @@ class Convert extends base_1.default {
|
|
|
28
27
|
// eslint-disable-next-line sonarjs/no-duplicate-string
|
|
29
28
|
this.metricsMetadata.to_version = flags['target-version'];
|
|
30
29
|
// Determine if the input is OpenAPI or AsyncAPI
|
|
31
|
-
const specJson = this.specFile.toJson();
|
|
32
30
|
const isOpenAPI = flags['format'] === 'openapi';
|
|
33
31
|
const isAsyncAPI = flags['format'] === 'asyncapi';
|
|
34
32
|
// CONVERSION
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
this.log(`🎉 The OpenAPI document has been successfully converted to AsyncAPI version ${(0, picocolors_1.green)(flags['target-version'])}!`);
|
|
40
|
-
}
|
|
41
|
-
else if (isAsyncAPI) {
|
|
42
|
-
convertedFile = (0, converter_1.convert)(this.specFile.text(), flags['target-version']);
|
|
43
|
-
if (this.specFile.getFilePath()) {
|
|
44
|
-
this.log(`🎉 The ${(0, picocolors_1.cyan)(this.specFile.getFilePath())} file has been successfully converted to version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
45
|
-
}
|
|
46
|
-
else if (this.specFile.getFileURL()) {
|
|
47
|
-
this.log(`🎉 The URL ${(0, picocolors_1.cyan)(this.specFile.getFileURL())} has been successfully converted to version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (typeof convertedFile === 'object') {
|
|
51
|
-
convertedFileFormatted = JSON.stringify(convertedFile, null, 4);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
convertedFileFormatted = convertedFile;
|
|
55
|
-
}
|
|
56
|
-
if (flags.output) {
|
|
57
|
-
yield fs_1.promises.writeFile(`${flags.output}`, convertedFileFormatted, { encoding: 'utf8' });
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
this.log(convertedFileFormatted);
|
|
61
|
-
}
|
|
33
|
+
convertedFile = this.handleConversion(isOpenAPI, isAsyncAPI, flags);
|
|
34
|
+
// Handle file output or log the result
|
|
35
|
+
convertedFileFormatted = this.formatConvertedFile(convertedFile);
|
|
36
|
+
yield this.handleOutput(flags.output, convertedFileFormatted);
|
|
62
37
|
}
|
|
63
38
|
catch (err) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
39
|
+
this.handleError(err, filePath !== null && filePath !== void 0 ? filePath : 'unknown', flags);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// Helper function to handle conversion logic
|
|
44
|
+
handleConversion(isOpenAPI, isAsyncAPI, flags) {
|
|
45
|
+
var _a;
|
|
46
|
+
const specJson = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.toJson();
|
|
47
|
+
if (isOpenAPI) {
|
|
48
|
+
return this.convertOpenAPI(specJson, flags);
|
|
49
|
+
}
|
|
50
|
+
else if (isAsyncAPI) {
|
|
51
|
+
return this.convertAsyncAPI(flags);
|
|
52
|
+
}
|
|
53
|
+
return this.convertPostman(flags);
|
|
54
|
+
}
|
|
55
|
+
convertOpenAPI(specJson, flags) {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
const convertedFile = (0, converter_1.convertOpenAPI)((_b = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : '', specJson.openapi, {
|
|
58
|
+
perspective: flags['perspective']
|
|
59
|
+
});
|
|
60
|
+
this.log(`🎉 The OpenAPI document has been successfully converted to AsyncAPI version ${(0, picocolors_1.green)(flags['target-version'])}!`);
|
|
61
|
+
return convertedFile;
|
|
62
|
+
}
|
|
63
|
+
convertAsyncAPI(flags) {
|
|
64
|
+
var _a, _b, _c, _d, _e, _f;
|
|
65
|
+
const convertedFile = (0, converter_1.convert)((_b = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : '', flags['target-version']);
|
|
66
|
+
if ((_c = this.specFile) === null || _c === void 0 ? void 0 : _c.getFilePath()) {
|
|
67
|
+
this.log(`🎉 The ${(0, picocolors_1.cyan)((_d = this.specFile) === null || _d === void 0 ? void 0 : _d.getFilePath())} file has been successfully converted to version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
68
|
+
}
|
|
69
|
+
else if ((_e = this.specFile) === null || _e === void 0 ? void 0 : _e.getFileURL()) {
|
|
70
|
+
this.log(`🎉 The URL ${(0, picocolors_1.cyan)((_f = this.specFile) === null || _f === void 0 ? void 0 : _f.getFileURL())} has been successfully converted to version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
71
|
+
}
|
|
72
|
+
return convertedFile;
|
|
73
|
+
}
|
|
74
|
+
convertPostman(flags) {
|
|
75
|
+
var _a, _b, _c, _d, _e, _f;
|
|
76
|
+
const convertedFile = (0, converter_1.convertPostman)((_b = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : '', '3.0.0', {
|
|
77
|
+
perspective: flags['perspective']
|
|
78
|
+
});
|
|
79
|
+
if ((_c = this.specFile) === null || _c === void 0 ? void 0 : _c.getFilePath()) {
|
|
80
|
+
this.log(`🎉 The ${(0, picocolors_1.cyan)((_d = this.specFile) === null || _d === void 0 ? void 0 : _d.getFilePath())} file has been successfully converted to asyncapi of version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
81
|
+
}
|
|
82
|
+
else if ((_e = this.specFile) === null || _e === void 0 ? void 0 : _e.getFileURL()) {
|
|
83
|
+
this.log(`🎉 The URL ${(0, picocolors_1.cyan)((_f = this.specFile) === null || _f === void 0 ? void 0 : _f.getFileURL())} has been successfully converted to asyncapi of version ${(0, picocolors_1.green)(flags['target-version'])}!!`);
|
|
84
|
+
}
|
|
85
|
+
return convertedFile;
|
|
86
|
+
}
|
|
87
|
+
// Helper function to format the converted file
|
|
88
|
+
formatConvertedFile(convertedFile) {
|
|
89
|
+
return typeof convertedFile === 'object' ? JSON.stringify(convertedFile, null, 4) : convertedFile;
|
|
90
|
+
}
|
|
91
|
+
// Helper function to handle output
|
|
92
|
+
handleOutput(outputPath, convertedFileFormatted) {
|
|
93
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
if (outputPath) {
|
|
95
|
+
yield fs_1.promises.writeFile(`${outputPath}`, convertedFileFormatted, { encoding: 'utf8' });
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this.log(convertedFileFormatted);
|
|
76
99
|
}
|
|
77
100
|
});
|
|
78
101
|
}
|
|
102
|
+
// Helper function to handle errors
|
|
103
|
+
handleError(err, filePath, flags) {
|
|
104
|
+
var _a;
|
|
105
|
+
if (err instanceof specification_file_1.SpecificationFileNotFound) {
|
|
106
|
+
this.error(new validation_error_1.ValidationError({
|
|
107
|
+
type: 'invalid-file',
|
|
108
|
+
filepath: filePath
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
else if (((_a = this.specFile) === null || _a === void 0 ? void 0 : _a.toJson().asyncapi) > flags['target-version']) {
|
|
112
|
+
this.error(`The ${(0, picocolors_1.cyan)(filePath)} file cannot be converted to an older version. Downgrading is not supported.`);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.error(err);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
79
118
|
}
|
|
80
119
|
exports.default = Convert;
|
|
81
|
-
Convert.
|
|
120
|
+
Convert.metricsMetadata = {};
|
|
121
|
+
Convert.description = 'Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI';
|
|
82
122
|
Convert.flags = (0, convert_flags_1.convertFlags)(latestVersion);
|
|
83
123
|
Convert.args = {
|
|
84
124
|
'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: false }),
|
|
@@ -9,7 +9,7 @@ const convertFlags = (latestVersion) => {
|
|
|
9
9
|
format: core_1.Flags.string({
|
|
10
10
|
char: 'f',
|
|
11
11
|
description: 'Specify the format to convert from (openapi or asyncapi)',
|
|
12
|
-
options: ['openapi', 'asyncapi'],
|
|
12
|
+
options: ['openapi', 'asyncapi', 'postman-collection'],
|
|
13
13
|
required: true,
|
|
14
14
|
default: 'asyncapi',
|
|
15
15
|
}),
|
package/oclif.manifest.json
CHANGED
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"required": false
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"description": "Convert asyncapi documents older to newer versions or OpenAPI documents to AsyncAPI",
|
|
78
|
+
"description": "Convert asyncapi documents older to newer versions or OpenAPI/postman-collection documents to AsyncAPI",
|
|
79
79
|
"flags": {
|
|
80
80
|
"help": {
|
|
81
81
|
"char": "h",
|
|
@@ -102,7 +102,8 @@
|
|
|
102
102
|
"multiple": false,
|
|
103
103
|
"options": [
|
|
104
104
|
"openapi",
|
|
105
|
-
"asyncapi"
|
|
105
|
+
"asyncapi",
|
|
106
|
+
"postman-collection"
|
|
106
107
|
],
|
|
107
108
|
"type": "option"
|
|
108
109
|
},
|
|
@@ -136,6 +137,7 @@
|
|
|
136
137
|
"pluginName": "@asyncapi/cli",
|
|
137
138
|
"pluginType": "core",
|
|
138
139
|
"strict": true,
|
|
140
|
+
"metricsMetadata": {},
|
|
139
141
|
"isESM": false,
|
|
140
142
|
"relativePath": [
|
|
141
143
|
"lib",
|
|
@@ -1620,5 +1622,5 @@
|
|
|
1620
1622
|
]
|
|
1621
1623
|
}
|
|
1622
1624
|
},
|
|
1623
|
-
"version": "2.
|
|
1625
|
+
"version": "2.6.0"
|
|
1624
1626
|
}
|