@asyncapi/cli 2.8.1 → 2.10.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 +11 -11
- package/assets/create-glee-app/templates/tutorial/package-lock.json +11 -11
- package/assets/create-template/templates/default/package-lock.json +32 -12
- package/lib/commands/diff.d.ts +2 -1
- package/lib/commands/format.d.ts +18 -0
- package/lib/commands/format.js +97 -0
- package/lib/commands/validate.d.ts +2 -1
- package/lib/core/errors/specification-file.d.ts +3 -0
- package/lib/core/errors/specification-file.js +8 -1
- package/lib/core/flags/diff.flags.d.ts +2 -1
- package/lib/core/flags/format.flags.d.ts +6 -0
- package/lib/core/flags/format.flags.js +22 -0
- package/lib/core/flags/validate.flags.d.ts +2 -1
- package/lib/core/models/SpecificationFile.d.ts +4 -0
- package/lib/core/models/SpecificationFile.js +40 -1
- package/lib/core/parser.d.ts +3 -1
- package/lib/core/parser.js +60 -14
- package/oclif.manifest.json +75 -3
- package/package.json +1 -1
|
@@ -5369,9 +5369,9 @@
|
|
|
5369
5369
|
"peer": true
|
|
5370
5370
|
},
|
|
5371
5371
|
"node_modules/cookie": {
|
|
5372
|
-
"version": "0.
|
|
5373
|
-
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.
|
|
5374
|
-
"integrity": "sha512-
|
|
5372
|
+
"version": "0.7.2",
|
|
5373
|
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
5374
|
+
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
5375
5375
|
"engines": {
|
|
5376
5376
|
"node": ">= 0.6"
|
|
5377
5377
|
}
|
|
@@ -5908,16 +5908,16 @@
|
|
|
5908
5908
|
}
|
|
5909
5909
|
},
|
|
5910
5910
|
"node_modules/engine.io": {
|
|
5911
|
-
"version": "6.
|
|
5912
|
-
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.
|
|
5913
|
-
"integrity": "sha512-
|
|
5911
|
+
"version": "6.6.2",
|
|
5912
|
+
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz",
|
|
5913
|
+
"integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==",
|
|
5914
5914
|
"dependencies": {
|
|
5915
5915
|
"@types/cookie": "^0.4.1",
|
|
5916
5916
|
"@types/cors": "^2.8.12",
|
|
5917
5917
|
"@types/node": ">=10.0.0",
|
|
5918
5918
|
"accepts": "~1.3.4",
|
|
5919
5919
|
"base64id": "2.0.0",
|
|
5920
|
-
"cookie": "~0.
|
|
5920
|
+
"cookie": "~0.7.2",
|
|
5921
5921
|
"cors": "~2.8.5",
|
|
5922
5922
|
"debug": "~4.3.1",
|
|
5923
5923
|
"engine.io-parser": "~5.2.1",
|
|
@@ -11794,15 +11794,15 @@
|
|
|
11794
11794
|
}
|
|
11795
11795
|
},
|
|
11796
11796
|
"node_modules/socket.io": {
|
|
11797
|
-
"version": "4.
|
|
11798
|
-
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.
|
|
11799
|
-
"integrity": "sha512-
|
|
11797
|
+
"version": "4.8.1",
|
|
11798
|
+
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz",
|
|
11799
|
+
"integrity": "sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg==",
|
|
11800
11800
|
"dependencies": {
|
|
11801
11801
|
"accepts": "~1.3.4",
|
|
11802
11802
|
"base64id": "~2.0.0",
|
|
11803
11803
|
"cors": "~2.8.5",
|
|
11804
11804
|
"debug": "~4.3.2",
|
|
11805
|
-
"engine.io": "~6.
|
|
11805
|
+
"engine.io": "~6.6.0",
|
|
11806
11806
|
"socket.io-adapter": "~2.5.2",
|
|
11807
11807
|
"socket.io-parser": "~4.2.4"
|
|
11808
11808
|
},
|
|
@@ -5366,9 +5366,9 @@
|
|
|
5366
5366
|
"peer": true
|
|
5367
5367
|
},
|
|
5368
5368
|
"node_modules/cookie": {
|
|
5369
|
-
"version": "0.
|
|
5370
|
-
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.
|
|
5371
|
-
"integrity": "sha512-
|
|
5369
|
+
"version": "0.7.2",
|
|
5370
|
+
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
|
5371
|
+
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
|
5372
5372
|
"engines": {
|
|
5373
5373
|
"node": ">= 0.6"
|
|
5374
5374
|
}
|
|
@@ -5905,16 +5905,16 @@
|
|
|
5905
5905
|
}
|
|
5906
5906
|
},
|
|
5907
5907
|
"node_modules/engine.io": {
|
|
5908
|
-
"version": "6.
|
|
5909
|
-
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.
|
|
5910
|
-
"integrity": "sha512-
|
|
5908
|
+
"version": "6.6.2",
|
|
5909
|
+
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz",
|
|
5910
|
+
"integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==",
|
|
5911
5911
|
"dependencies": {
|
|
5912
5912
|
"@types/cookie": "^0.4.1",
|
|
5913
5913
|
"@types/cors": "^2.8.12",
|
|
5914
5914
|
"@types/node": ">=10.0.0",
|
|
5915
5915
|
"accepts": "~1.3.4",
|
|
5916
5916
|
"base64id": "2.0.0",
|
|
5917
|
-
"cookie": "~0.
|
|
5917
|
+
"cookie": "~0.7.2",
|
|
5918
5918
|
"cors": "~2.8.5",
|
|
5919
5919
|
"debug": "~4.3.1",
|
|
5920
5920
|
"engine.io-parser": "~5.2.1",
|
|
@@ -11791,15 +11791,15 @@
|
|
|
11791
11791
|
}
|
|
11792
11792
|
},
|
|
11793
11793
|
"node_modules/socket.io": {
|
|
11794
|
-
"version": "4.
|
|
11795
|
-
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.
|
|
11796
|
-
"integrity": "sha512-
|
|
11794
|
+
"version": "4.8.0",
|
|
11795
|
+
"resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.0.tgz",
|
|
11796
|
+
"integrity": "sha512-8U6BEgGjQOfGz3HHTYaC/L1GaxDCJ/KM0XTkJly0EhZ5U/du9uNEZy4ZgYzEzIqlx2CMm25CrCqr1ck899eLNA==",
|
|
11797
11797
|
"dependencies": {
|
|
11798
11798
|
"accepts": "~1.3.4",
|
|
11799
11799
|
"base64id": "~2.0.0",
|
|
11800
11800
|
"cors": "~2.8.5",
|
|
11801
11801
|
"debug": "~4.3.2",
|
|
11802
|
-
"engine.io": "~6.
|
|
11802
|
+
"engine.io": "~6.6.0",
|
|
11803
11803
|
"socket.io-adapter": "~2.5.2",
|
|
11804
11804
|
"socket.io-parser": "~4.2.4"
|
|
11805
11805
|
},
|
|
@@ -91,11 +91,11 @@
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
"node_modules/@asyncapi/parser": {
|
|
94
|
-
"version": "3.
|
|
95
|
-
"resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.
|
|
96
|
-
"integrity": "sha512-
|
|
94
|
+
"version": "3.4.0",
|
|
95
|
+
"resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.4.0.tgz",
|
|
96
|
+
"integrity": "sha512-Sxn74oHiZSU6+cVeZy62iPZMFMvKp4jupMFHelSICCMw1qELmUHPvuZSr+ZHDmNGgHcEpzJM5HN02kR7T4g+PQ==",
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"@asyncapi/specs": "^6.
|
|
98
|
+
"@asyncapi/specs": "^6.8.0",
|
|
99
99
|
"@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0",
|
|
100
100
|
"@stoplight/json": "3.21.0",
|
|
101
101
|
"@stoplight/json-ref-readers": "^1.2.2",
|
|
@@ -112,14 +112,14 @@
|
|
|
112
112
|
"ajv-formats": "^2.1.1",
|
|
113
113
|
"avsc": "^5.7.5",
|
|
114
114
|
"js-yaml": "^4.1.0",
|
|
115
|
-
"jsonpath-plus": "^
|
|
115
|
+
"jsonpath-plus": "^10.0.0",
|
|
116
116
|
"node-fetch": "2.6.7"
|
|
117
117
|
}
|
|
118
118
|
},
|
|
119
119
|
"node_modules/@asyncapi/specs": {
|
|
120
|
-
"version": "6.
|
|
121
|
-
"resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.
|
|
122
|
-
"integrity": "sha512-
|
|
120
|
+
"version": "6.8.0",
|
|
121
|
+
"resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.8.0.tgz",
|
|
122
|
+
"integrity": "sha512-1i6xs8+IOh6U5T7yH+bCMGQBF+m7kP/NpwyAlt++XaDQutoGCgACf24mQBgcDVqDWWoY81evQv+9ABvw0BviVg==",
|
|
123
123
|
"dependencies": {
|
|
124
124
|
"@types/json-schema": "^7.0.11"
|
|
125
125
|
}
|
|
@@ -1813,6 +1813,17 @@
|
|
|
1813
1813
|
"@jridgewell/sourcemap-codec": "^1.4.14"
|
|
1814
1814
|
}
|
|
1815
1815
|
},
|
|
1816
|
+
"node_modules/@jsep-plugin/assignment": {
|
|
1817
|
+
"version": "1.3.0",
|
|
1818
|
+
"resolved": "https://registry.npmjs.org/@jsep-plugin/assignment/-/assignment-1.3.0.tgz",
|
|
1819
|
+
"integrity": "sha512-VVgV+CXrhbMI3aSusQyclHkenWSAm95WaiKrMxRFam3JSUiIaQjoMIw2sEs/OX4XifnqeQUN4DYbJjlA8EfktQ==",
|
|
1820
|
+
"engines": {
|
|
1821
|
+
"node": ">= 10.16.0"
|
|
1822
|
+
},
|
|
1823
|
+
"peerDependencies": {
|
|
1824
|
+
"jsep": "^0.4.0||^1.0.0"
|
|
1825
|
+
}
|
|
1826
|
+
},
|
|
1816
1827
|
"node_modules/@jsep-plugin/regex": {
|
|
1817
1828
|
"version": "1.0.3",
|
|
1818
1829
|
"resolved": "https://registry.npmjs.org/@jsep-plugin/regex/-/regex-1.0.3.tgz",
|
|
@@ -3344,11 +3355,20 @@
|
|
|
3344
3355
|
"integrity": "sha512-o6/yDBYccGvTz1+QFevz6l6OBZ2+fMVu2JZ9CIhzsYRX4mjaK5IyX9eldUdCmga16zlgQxyrj5pt9kzuj2C02w=="
|
|
3345
3356
|
},
|
|
3346
3357
|
"node_modules/jsonpath-plus": {
|
|
3347
|
-
"version": "
|
|
3348
|
-
"resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-
|
|
3349
|
-
"integrity": "sha512-
|
|
3358
|
+
"version": "10.1.0",
|
|
3359
|
+
"resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-10.1.0.tgz",
|
|
3360
|
+
"integrity": "sha512-gHfV1IYqH8uJHYVTs8BJX1XKy2/rR93+f8QQi0xhx95aCiXn1ettYAd5T+7FU6wfqyDoX/wy0pm/fL3jOKJ9Lg==",
|
|
3361
|
+
"dependencies": {
|
|
3362
|
+
"@jsep-plugin/assignment": "^1.2.1",
|
|
3363
|
+
"@jsep-plugin/regex": "^1.0.3",
|
|
3364
|
+
"jsep": "^1.3.9"
|
|
3365
|
+
},
|
|
3366
|
+
"bin": {
|
|
3367
|
+
"jsonpath": "bin/jsonpath-cli.js",
|
|
3368
|
+
"jsonpath-plus": "bin/jsonpath-cli.js"
|
|
3369
|
+
},
|
|
3350
3370
|
"engines": {
|
|
3351
|
-
"node": ">=
|
|
3371
|
+
"node": ">=18.0.0"
|
|
3352
3372
|
}
|
|
3353
3373
|
},
|
|
3354
3374
|
"node_modules/jsonpointer": {
|
package/lib/commands/diff.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export default class Diff extends Command {
|
|
|
5
5
|
static flags: {
|
|
6
6
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
7
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
8
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
10
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
11
|
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
11
12
|
type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import Command from '../core/base';
|
|
2
|
+
export default class Convert extends Command {
|
|
3
|
+
static specFile: any;
|
|
4
|
+
static metricsMetadata: any;
|
|
5
|
+
static description: string;
|
|
6
|
+
static flags: {
|
|
7
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
8
|
+
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
10
|
+
};
|
|
11
|
+
static args: {
|
|
12
|
+
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private handleConversion;
|
|
16
|
+
private handleOutput;
|
|
17
|
+
private removeExtensionFromOutputPath;
|
|
18
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
5
|
+
const fs_1 = require("fs");
|
|
6
|
+
const core_1 = require("@oclif/core");
|
|
7
|
+
const base_1 = tslib_1.__importDefault(require("../core/base"));
|
|
8
|
+
const SpecificationFile_1 = require("../core/models/SpecificationFile");
|
|
9
|
+
const specification_file_1 = require("../core/errors/specification-file");
|
|
10
|
+
const picocolors_1 = require("picocolors");
|
|
11
|
+
const format_flags_1 = require("../core/flags/format.flags");
|
|
12
|
+
class Convert extends base_1.default {
|
|
13
|
+
run() {
|
|
14
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const { args, flags } = yield this.parse(Convert);
|
|
16
|
+
const filePath = args['spec-file'];
|
|
17
|
+
const outputFileFormat = flags['format'];
|
|
18
|
+
let convertedFile;
|
|
19
|
+
try {
|
|
20
|
+
this.specFile = yield (0, SpecificationFile_1.load)(filePath);
|
|
21
|
+
// eslint-disable-next-line sonarjs/no-duplicate-string
|
|
22
|
+
this.metricsMetadata.to_version = flags['target-version'];
|
|
23
|
+
const ff = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
|
|
24
|
+
const isSpecFileJson = ff === 'json';
|
|
25
|
+
const isSpecFileYaml = ff === 'yaml';
|
|
26
|
+
if (!isSpecFileJson && !isSpecFileYaml) {
|
|
27
|
+
throw new specification_file_1.SpecificationWrongFileFormat(filePath);
|
|
28
|
+
}
|
|
29
|
+
convertedFile = this.handleConversion(isSpecFileJson, isSpecFileYaml, outputFileFormat);
|
|
30
|
+
if (!convertedFile) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
yield this.handleOutput(flags.output, convertedFile, outputFileFormat);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
this.error(err);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
handleConversion(isSpecFileJson, isSpecFileYaml, outputFileFormat) {
|
|
41
|
+
var _a;
|
|
42
|
+
const text = (_a = this.specFile) === null || _a === void 0 ? void 0 : _a.text();
|
|
43
|
+
if (isSpecFileJson && text) {
|
|
44
|
+
if (outputFileFormat === 'json') {
|
|
45
|
+
throw new Error(`Your document is already a ${(0, picocolors_1.cyan)('JSON')}`);
|
|
46
|
+
}
|
|
47
|
+
return (0, SpecificationFile_1.convertToYaml)(text);
|
|
48
|
+
}
|
|
49
|
+
if (isSpecFileYaml && text) {
|
|
50
|
+
if (outputFileFormat === 'yaml' || outputFileFormat === 'yml') {
|
|
51
|
+
throw new Error(`Your document is already a ${(0, picocolors_1.cyan)('YAML')}`);
|
|
52
|
+
}
|
|
53
|
+
return (0, SpecificationFile_1.convertToJSON)(text);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
handleOutput(outputPath, formattedFile, outputFileFormat) {
|
|
57
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
if (outputPath) {
|
|
59
|
+
outputPath = this.removeExtensionFromOutputPath(outputPath);
|
|
60
|
+
const finalFileName = `${outputPath}.${outputFileFormat}`;
|
|
61
|
+
yield fs_1.promises.writeFile(finalFileName, formattedFile, {
|
|
62
|
+
encoding: 'utf8',
|
|
63
|
+
});
|
|
64
|
+
this.log(`succesfully formatted to ${outputFileFormat} at ${(0, picocolors_1.green)(finalFileName)} ✅`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.log(formattedFile);
|
|
68
|
+
this.log(`succesfully logged after formatting to ${outputFileFormat} ✅`);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
removeExtensionFromOutputPath(filename) {
|
|
73
|
+
var _a;
|
|
74
|
+
// Removes the extension from a filename if it is .json, .yaml, or .yml
|
|
75
|
+
// this is so that we can remove the provided extension name in the -o flag and
|
|
76
|
+
// apply our own extension name according to the content of the file
|
|
77
|
+
const validExtensions = ['json', 'yaml', 'yml'];
|
|
78
|
+
const parts = filename.split('.');
|
|
79
|
+
if (parts.length > 1) {
|
|
80
|
+
const extension = (_a = parts.pop()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
81
|
+
if (extension && validExtensions.includes(extension)) {
|
|
82
|
+
return parts.join('.');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return filename;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.default = Convert;
|
|
89
|
+
Convert.metricsMetadata = {};
|
|
90
|
+
Convert.description = 'Convert asyncapi documents from any format to yaml, yml or JSON';
|
|
91
|
+
Convert.flags = (0, format_flags_1.convertFormatFlags)();
|
|
92
|
+
Convert.args = {
|
|
93
|
+
'spec-file': core_1.Args.string({
|
|
94
|
+
description: 'spec path, url, or context-name',
|
|
95
|
+
required: false,
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
@@ -5,7 +5,8 @@ export default class Validate extends Command {
|
|
|
5
5
|
score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
6
6
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
7
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
8
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
9
10
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
10
11
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
11
12
|
};
|
|
@@ -4,6 +4,9 @@ declare class SpecificationFileError extends Error {
|
|
|
4
4
|
export declare class SpecificationFileNotFound extends SpecificationFileError {
|
|
5
5
|
constructor(filePath?: string);
|
|
6
6
|
}
|
|
7
|
+
export declare class SpecificationWrongFileFormat extends SpecificationFileError {
|
|
8
|
+
constructor(filePath?: string);
|
|
9
|
+
}
|
|
7
10
|
export declare class SpecificationURLNotFound extends SpecificationFileError {
|
|
8
11
|
constructor(URL: string);
|
|
9
12
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrorLoadingSpec = exports.SpecificationURLNotFound = exports.SpecificationFileNotFound = void 0;
|
|
3
|
+
exports.ErrorLoadingSpec = exports.SpecificationURLNotFound = exports.SpecificationWrongFileFormat = exports.SpecificationFileNotFound = void 0;
|
|
4
4
|
const context_error_1 = require("./context-error");
|
|
5
5
|
class SpecificationFileError extends Error {
|
|
6
6
|
constructor() {
|
|
@@ -20,6 +20,13 @@ class SpecificationFileNotFound extends SpecificationFileError {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.SpecificationFileNotFound = SpecificationFileNotFound;
|
|
23
|
+
class SpecificationWrongFileFormat extends SpecificationFileError {
|
|
24
|
+
constructor(filePath) {
|
|
25
|
+
super();
|
|
26
|
+
this.message = `File ${filePath} is not of correct format.`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SpecificationWrongFileFormat = SpecificationWrongFileFormat;
|
|
23
30
|
class SpecificationURLNotFound extends SpecificationFileError {
|
|
24
31
|
constructor(URL) {
|
|
25
32
|
super();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export declare const diffFlags: () => {
|
|
2
2
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
3
3
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
4
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
4
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
6
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
6
7
|
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
7
8
|
type: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type fileFormat = 'yaml' | 'yml' | 'json';
|
|
2
|
+
export declare const convertFormatFlags: () => {
|
|
3
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
4
|
+
format: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertFormatFlags = void 0;
|
|
4
|
+
const core_1 = require("@oclif/core");
|
|
5
|
+
const availFileFormats = ['yaml', 'yml', 'json'];
|
|
6
|
+
const convertFormatFlags = () => {
|
|
7
|
+
return {
|
|
8
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
9
|
+
format: core_1.Flags.string({
|
|
10
|
+
char: 'f',
|
|
11
|
+
description: 'Specify the format to convert to',
|
|
12
|
+
options: availFileFormats,
|
|
13
|
+
required: true,
|
|
14
|
+
default: 'json',
|
|
15
|
+
}),
|
|
16
|
+
output: core_1.Flags.string({
|
|
17
|
+
char: 'o',
|
|
18
|
+
description: 'path to the file where the result is saved',
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.convertFormatFlags = convertFormatFlags;
|
|
@@ -2,7 +2,8 @@ export declare const validateFlags: () => {
|
|
|
2
2
|
score: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
3
3
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
4
4
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<import("@stoplight/spectral-cli/dist/services/config").OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
5
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
5
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
6
7
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
7
8
|
watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
8
9
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileFormat } from 'core/flags/format.flags';
|
|
1
2
|
export declare class Specification {
|
|
2
3
|
private readonly spec;
|
|
3
4
|
private readonly filePath?;
|
|
@@ -33,4 +34,7 @@ export declare function load(filePathOrContextName?: string, loadType?: LoadType
|
|
|
33
34
|
export declare function nameType(name: string): Promise<string>;
|
|
34
35
|
export declare function isURL(urlpath: string): Promise<boolean>;
|
|
35
36
|
export declare function fileExists(name: string): Promise<boolean>;
|
|
37
|
+
export declare function retrieveFileFormat(content: string): fileFormat | undefined;
|
|
38
|
+
export declare function convertToYaml(spec: string): string | undefined;
|
|
39
|
+
export declare function convertToJSON(spec: string): string | undefined;
|
|
36
40
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fileExists = exports.isURL = exports.nameType = exports.load = exports.Specification = void 0;
|
|
3
|
+
exports.convertToJSON = exports.convertToYaml = exports.retrieveFileFormat = exports.fileExists = exports.isURL = exports.nameType = exports.load = exports.Specification = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
@@ -226,3 +226,42 @@ function detectSpecFile() {
|
|
|
226
226
|
return existingFileNames.find(filename => filename !== undefined);
|
|
227
227
|
});
|
|
228
228
|
}
|
|
229
|
+
function retrieveFileFormat(content) {
|
|
230
|
+
try {
|
|
231
|
+
if (content.trimStart()[0] === '{') {
|
|
232
|
+
JSON.parse(content);
|
|
233
|
+
return 'json';
|
|
234
|
+
}
|
|
235
|
+
// below yaml.load is not a definitive way to determine if a file is yaml or not.
|
|
236
|
+
// it is able to load .txt text files also.
|
|
237
|
+
js_yaml_1.default.load(content);
|
|
238
|
+
return 'yaml';
|
|
239
|
+
}
|
|
240
|
+
catch (err) {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
exports.retrieveFileFormat = retrieveFileFormat;
|
|
245
|
+
function convertToYaml(spec) {
|
|
246
|
+
try {
|
|
247
|
+
// JS object -> YAML string
|
|
248
|
+
const jsonContent = js_yaml_1.default.load(spec);
|
|
249
|
+
return js_yaml_1.default.dump(jsonContent);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
console.error(err);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
exports.convertToYaml = convertToYaml;
|
|
256
|
+
function convertToJSON(spec) {
|
|
257
|
+
try {
|
|
258
|
+
// JSON or YAML String -> JS object
|
|
259
|
+
const jsonContent = js_yaml_1.default.load(spec);
|
|
260
|
+
// JS Object -> pretty JSON string
|
|
261
|
+
return JSON.stringify(jsonContent, null, 2);
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
console.error(err);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.convertToJSON = convertToJSON;
|
package/lib/core/parser.d.ts
CHANGED
|
@@ -15,12 +15,14 @@ export declare enum ValidationStatus {
|
|
|
15
15
|
export declare function validationFlags({ logDiagnostics }?: ValidationFlagsOptions): {
|
|
16
16
|
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
17
17
|
'diagnostics-format': import("@oclif/core/lib/interfaces").OptionFlag<OutputFormat, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
18
|
-
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"
|
|
18
|
+
'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
|
+
output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
19
20
|
};
|
|
20
21
|
export interface ValidateOptions {
|
|
21
22
|
'log-diagnostics'?: boolean;
|
|
22
23
|
'diagnostics-format'?: `${OutputFormat}`;
|
|
23
24
|
'fail-severity'?: SeverityKind;
|
|
25
|
+
'output'?: string;
|
|
24
26
|
}
|
|
25
27
|
export declare function validate(command: Command, specFile: Specification, options?: ValidateOptions): Promise<"valid" | "invalid">;
|
|
26
28
|
export declare function parse(command: Command, specFile: Specification, options?: ValidateOptions): Promise<{
|
package/lib/core/parser.js
CHANGED
|
@@ -13,6 +13,19 @@ const spectral_core_1 = require("@stoplight/spectral-core");
|
|
|
13
13
|
const config_1 = require("@stoplight/spectral-cli/dist/services/config");
|
|
14
14
|
const spectral_formatters_1 = require("@stoplight/spectral-formatters");
|
|
15
15
|
const chalk_1 = require("chalk");
|
|
16
|
+
const fs_1 = require("fs");
|
|
17
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
18
|
+
const { writeFile } = fs_1.promises;
|
|
19
|
+
const formatExtensions = {
|
|
20
|
+
stylish: '.txt',
|
|
21
|
+
json: '.json',
|
|
22
|
+
junit: '.xml',
|
|
23
|
+
html: '.html',
|
|
24
|
+
text: '.txt',
|
|
25
|
+
teamcity: '.txt',
|
|
26
|
+
pretty: '.txt',
|
|
27
|
+
};
|
|
28
|
+
const validFormats = ['stylish', 'json', 'junit', 'html', 'text', 'teamcity', 'pretty'];
|
|
16
29
|
const parser = new cjs_1.Parser({
|
|
17
30
|
__unstable: {
|
|
18
31
|
resolver: {
|
|
@@ -46,6 +59,10 @@ function validationFlags({ logDiagnostics = true } = {}) {
|
|
|
46
59
|
options: ['error', 'warn', 'info', 'hint'],
|
|
47
60
|
default: 'error',
|
|
48
61
|
})(),
|
|
62
|
+
output: core_1.Flags.string({
|
|
63
|
+
description: 'The output file name. Omitting this flag the result will be printed in the console.',
|
|
64
|
+
char: 'o'
|
|
65
|
+
})
|
|
49
66
|
};
|
|
50
67
|
}
|
|
51
68
|
exports.validationFlags = validationFlags;
|
|
@@ -70,23 +87,33 @@ function logDiagnostics(diagnostics, command, specFile, options = {}) {
|
|
|
70
87
|
const failSeverity = (_a = options['fail-severity']) !== null && _a !== void 0 ? _a : 'error';
|
|
71
88
|
const diagnosticsFormat = (_b = options['diagnostics-format']) !== null && _b !== void 0 ? _b : 'stylish';
|
|
72
89
|
const sourceString = specFile.toSourceString();
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return ValidationStatus.INVALID;
|
|
80
|
-
}
|
|
81
|
-
if (logDiagnostics) {
|
|
82
|
-
command.log(`\n${sourceString} is valid but has (itself and/or referenced documents) governance issues.`);
|
|
83
|
-
command.log(formatOutput(diagnostics, diagnosticsFormat, failSeverity));
|
|
84
|
-
}
|
|
90
|
+
const hasIssues = diagnostics.length > 0;
|
|
91
|
+
const isFailSeverity = hasIssues && hasFailSeverity(diagnostics, failSeverity);
|
|
92
|
+
if (logDiagnostics) {
|
|
93
|
+
logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity);
|
|
94
|
+
outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options);
|
|
85
95
|
}
|
|
86
|
-
|
|
96
|
+
return isFailSeverity ? ValidationStatus.INVALID : ValidationStatus.VALID;
|
|
97
|
+
}
|
|
98
|
+
function logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity) {
|
|
99
|
+
if (!hasIssues) {
|
|
87
100
|
command.log(`\n${sourceString} is valid! ${sourceString} and referenced documents don't have governance issues.`);
|
|
88
101
|
}
|
|
89
|
-
|
|
102
|
+
else if (isFailSeverity) {
|
|
103
|
+
command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
command.log(`\n${sourceString} is valid but has (itself and/or referenced documents) governance issues.`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options) {
|
|
110
|
+
const diagnosticsOutput = formatOutput(diagnostics, diagnosticsFormat, failSeverity);
|
|
111
|
+
if (options.output) {
|
|
112
|
+
writeValidationDiagnostic(options.output, command, diagnosticsFormat, diagnosticsOutput);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
command.log(diagnosticsOutput);
|
|
116
|
+
}
|
|
90
117
|
}
|
|
91
118
|
function formatOutput(diagnostics, format, failSeverity) {
|
|
92
119
|
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
@@ -128,3 +155,22 @@ function hasFailSeverity(diagnostics, failSeverity) {
|
|
|
128
155
|
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
129
156
|
return diagnostics.some(diagnostic => diagnostic.severity <= diagnosticSeverity);
|
|
130
157
|
}
|
|
158
|
+
function writeValidationDiagnostic(outputPath, command, format, formatOutput) {
|
|
159
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
if (!validFormats.includes(format)) {
|
|
161
|
+
command.logToStderr(`Invalid diagnostics format: "${format}"`);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const expectedExtension = formatExtensions[format];
|
|
165
|
+
const actualExtension = path_1.default.extname(outputPath);
|
|
166
|
+
// Validate file extension against diagnostics format
|
|
167
|
+
if (expectedExtension && (actualExtension !== expectedExtension)) {
|
|
168
|
+
command.logToStderr(`Invalid file extension for format "${format}". Expected extension: "${expectedExtension}"`);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
yield writeFile(path_1.default.resolve(process.cwd(), outputPath), formatOutput, {
|
|
172
|
+
encoding: 'utf-8',
|
|
173
|
+
}).catch(err => console.log(err));
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -267,6 +267,14 @@
|
|
|
267
267
|
"hint"
|
|
268
268
|
],
|
|
269
269
|
"type": "option"
|
|
270
|
+
},
|
|
271
|
+
"output": {
|
|
272
|
+
"char": "o",
|
|
273
|
+
"description": "The output file name. Omitting this flag the result will be printed in the console.",
|
|
274
|
+
"name": "output",
|
|
275
|
+
"hasDynamicHelp": false,
|
|
276
|
+
"multiple": false,
|
|
277
|
+
"type": "option"
|
|
270
278
|
}
|
|
271
279
|
},
|
|
272
280
|
"hasDynamicHelp": false,
|
|
@@ -283,6 +291,63 @@
|
|
|
283
291
|
"diff.js"
|
|
284
292
|
]
|
|
285
293
|
},
|
|
294
|
+
"format": {
|
|
295
|
+
"aliases": [],
|
|
296
|
+
"args": {
|
|
297
|
+
"spec-file": {
|
|
298
|
+
"description": "spec path, url, or context-name",
|
|
299
|
+
"name": "spec-file",
|
|
300
|
+
"required": false
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
"description": "Convert asyncapi documents from any format to yaml, yml or JSON",
|
|
304
|
+
"flags": {
|
|
305
|
+
"help": {
|
|
306
|
+
"char": "h",
|
|
307
|
+
"description": "Show CLI help.",
|
|
308
|
+
"name": "help",
|
|
309
|
+
"allowNo": false,
|
|
310
|
+
"type": "boolean"
|
|
311
|
+
},
|
|
312
|
+
"format": {
|
|
313
|
+
"char": "f",
|
|
314
|
+
"description": "Specify the format to convert to",
|
|
315
|
+
"name": "format",
|
|
316
|
+
"required": true,
|
|
317
|
+
"default": "json",
|
|
318
|
+
"hasDynamicHelp": false,
|
|
319
|
+
"multiple": false,
|
|
320
|
+
"options": [
|
|
321
|
+
"yaml",
|
|
322
|
+
"yml",
|
|
323
|
+
"json"
|
|
324
|
+
],
|
|
325
|
+
"type": "option"
|
|
326
|
+
},
|
|
327
|
+
"output": {
|
|
328
|
+
"char": "o",
|
|
329
|
+
"description": "path to the file where the result is saved",
|
|
330
|
+
"name": "output",
|
|
331
|
+
"hasDynamicHelp": false,
|
|
332
|
+
"multiple": false,
|
|
333
|
+
"type": "option"
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
"hasDynamicHelp": false,
|
|
337
|
+
"hiddenAliases": [],
|
|
338
|
+
"id": "format",
|
|
339
|
+
"pluginAlias": "@asyncapi/cli",
|
|
340
|
+
"pluginName": "@asyncapi/cli",
|
|
341
|
+
"pluginType": "core",
|
|
342
|
+
"strict": true,
|
|
343
|
+
"metricsMetadata": {},
|
|
344
|
+
"isESM": false,
|
|
345
|
+
"relativePath": [
|
|
346
|
+
"lib",
|
|
347
|
+
"commands",
|
|
348
|
+
"format.js"
|
|
349
|
+
]
|
|
350
|
+
},
|
|
286
351
|
"optimize": {
|
|
287
352
|
"aliases": [],
|
|
288
353
|
"args": {
|
|
@@ -437,6 +502,14 @@
|
|
|
437
502
|
],
|
|
438
503
|
"type": "option"
|
|
439
504
|
},
|
|
505
|
+
"output": {
|
|
506
|
+
"char": "o",
|
|
507
|
+
"description": "The output file name. Omitting this flag the result will be printed in the console.",
|
|
508
|
+
"name": "output",
|
|
509
|
+
"hasDynamicHelp": false,
|
|
510
|
+
"multiple": false,
|
|
511
|
+
"type": "option"
|
|
512
|
+
},
|
|
440
513
|
"score": {
|
|
441
514
|
"description": "Compute the score of the AsyncAPI document. Scoring is based on whether the document has description, license, server and/or channels.",
|
|
442
515
|
"name": "score",
|
|
@@ -757,9 +830,8 @@
|
|
|
757
830
|
},
|
|
758
831
|
"output": {
|
|
759
832
|
"char": "o",
|
|
760
|
-
"description": "The output
|
|
833
|
+
"description": "The output file name. Omitting this flag the result will be printed in the console.",
|
|
761
834
|
"name": "output",
|
|
762
|
-
"required": false,
|
|
763
835
|
"hasDynamicHelp": false,
|
|
764
836
|
"multiple": false,
|
|
765
837
|
"type": "option"
|
|
@@ -1622,5 +1694,5 @@
|
|
|
1622
1694
|
]
|
|
1623
1695
|
}
|
|
1624
1696
|
},
|
|
1625
|
-
"version": "2.
|
|
1697
|
+
"version": "2.10.0"
|
|
1626
1698
|
}
|