@asyncapi/cli 2.9.0 → 2.11.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.
@@ -5462,9 +5462,9 @@
5462
5462
  }
5463
5463
  },
5464
5464
  "node_modules/cross-spawn": {
5465
- "version": "7.0.3",
5466
- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
5467
- "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
5465
+ "version": "7.0.6",
5466
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
5467
+ "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
5468
5468
  "dependencies": {
5469
5469
  "path-key": "^3.1.0",
5470
5470
  "shebang-command": "^2.0.0",
@@ -5459,9 +5459,9 @@
5459
5459
  }
5460
5460
  },
5461
5461
  "node_modules/cross-spawn": {
5462
- "version": "7.0.3",
5463
- "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
5464
- "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==",
5462
+ "version": "7.0.5",
5463
+ "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz",
5464
+ "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==",
5465
5465
  "dependencies": {
5466
5466
  "path-key": "^3.1.0",
5467
5467
  "shebang-command": "^2.0.0",
@@ -91,11 +91,11 @@
91
91
  }
92
92
  },
93
93
  "node_modules/@asyncapi/parser": {
94
- "version": "3.2.2",
95
- "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.2.2.tgz",
96
- "integrity": "sha512-ved4ja3ANs6BcRhWLbK/A7JIhJyMQBYdV1GZwo6Ptf+qBkGIdvV3dt8M4T6TZqtIbUI2NOvmO2YUqtaPWTudgA==",
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.6.0",
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": "^7.2.0",
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.7.1",
121
- "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.7.1.tgz",
122
- "integrity": "sha512-jEaW2vgAwD9GboCdO/TI1zN2k+iowL8YFYwiZwTIr4U4KDmsgo3BLypScl6Jl4+IvY9RdsWE67nuzVX7jooiqQ==",
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": "7.2.0",
3348
- "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz",
3349
- "integrity": "sha512-zBfiUPM5nD0YZSBT/o/fbCUlCcepMIdP0CJZxM1+KgA4f2T206f6VAg9e7mX35+KlMaIc5qXW34f3BnwJ3w+RA==",
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": ">=12.0.0"
3371
+ "node": ">=18.0.0"
3352
3372
  }
3353
3373
  },
3354
3374
  "node_modules/jsonpointer": {
@@ -5,7 +5,7 @@ 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<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
11
11
  format: 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
+ };
@@ -0,0 +1,12 @@
1
+ import Command from '../core/base';
2
+ export default class Pretty extends Command {
3
+ static readonly description = "Format AsyncAPI specification file";
4
+ static readonly examples: string[];
5
+ static readonly flags: {
6
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
+ };
8
+ static readonly args: {
9
+ 'spec-file': import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const core_1 = require("@oclif/core");
5
+ const fs_1 = require("fs");
6
+ const yaml = tslib_1.__importStar(require("yaml"));
7
+ const base_1 = tslib_1.__importDefault(require("../core/base"));
8
+ const SpecificationFile_1 = require("../core/models/SpecificationFile");
9
+ const validation_error_1 = require("../core/errors/validation-error");
10
+ const pretty_flags_1 = require("../core/flags/pretty.flags");
11
+ class Pretty extends base_1.default {
12
+ run() {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ const { args, flags } = yield this.parse(Pretty);
15
+ const filePath = args['spec-file'];
16
+ const outputPath = flags.output;
17
+ try {
18
+ this.specFile = yield (0, SpecificationFile_1.load)(filePath);
19
+ }
20
+ catch (err) {
21
+ this.error(new validation_error_1.ValidationError({
22
+ type: 'invalid-file',
23
+ filepath: filePath,
24
+ }));
25
+ }
26
+ const content = this.specFile.text();
27
+ let formatted;
28
+ try {
29
+ const fileFormat = (0, SpecificationFile_1.retrieveFileFormat)(this.specFile.text());
30
+ if (fileFormat === 'yaml' || fileFormat === 'yml') {
31
+ const yamlDoc = yaml.parseDocument(content);
32
+ formatted = yamlDoc.toString({
33
+ lineWidth: 0,
34
+ });
35
+ }
36
+ else if (fileFormat === 'json') {
37
+ const jsonObj = JSON.parse(content);
38
+ formatted = JSON.stringify(jsonObj, null, 2);
39
+ }
40
+ else {
41
+ throw new Error('Unsupported file format');
42
+ }
43
+ }
44
+ catch (err) {
45
+ this.error(`Error formatting file: ${err}`);
46
+ }
47
+ if (outputPath) {
48
+ yield fs_1.promises.writeFile(outputPath, formatted, 'utf8');
49
+ this.log(`Asyncapi document has been beautified ${outputPath}`);
50
+ }
51
+ else {
52
+ yield fs_1.promises.writeFile(filePath, formatted, 'utf8');
53
+ this.log(`Asyncapi document ${filePath} has been beautified in-place.`);
54
+ }
55
+ });
56
+ }
57
+ }
58
+ exports.default = Pretty;
59
+ Pretty.description = 'Format AsyncAPI specification file';
60
+ Pretty.examples = [
61
+ 'asyncapi pretty ./asyncapi.yaml',
62
+ 'asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml',
63
+ ];
64
+ Pretty.flags = (0, pretty_flags_1.prettyFlags)();
65
+ Pretty.args = {
66
+ 'spec-file': core_1.Args.string({ description: 'spec path, url, or context-name', required: true }),
67
+ };
@@ -5,7 +5,7 @@ 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<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
8
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
9
9
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
10
10
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
11
11
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -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,7 @@
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<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
4
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
5
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
6
6
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
7
7
  format: 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;
@@ -0,0 +1,3 @@
1
+ export declare const prettyFlags: () => {
2
+ output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
3
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prettyFlags = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const prettyFlags = () => {
6
+ return {
7
+ output: core_1.Flags.string({
8
+ char: 'o',
9
+ description: 'Output file path',
10
+ }),
11
+ };
12
+ };
13
+ exports.prettyFlags = prettyFlags;
@@ -2,7 +2,7 @@ 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<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
5
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
6
6
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
7
7
  help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
8
8
  watch: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
@@ -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;
@@ -15,7 +15,7 @@ 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<"error" | "warn" | "info" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
18
+ 'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"info" | "error" | "warn" | "hint", import("@oclif/core/lib/interfaces").CustomOptions>;
19
19
  output: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
20
20
  };
21
21
  export interface ValidateOptions {
@@ -291,6 +291,63 @@
291
291
  "diff.js"
292
292
  ]
293
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
+ },
294
351
  "optimize": {
295
352
  "aliases": [],
296
353
  "args": {
@@ -383,6 +440,44 @@
383
440
  "optimize.js"
384
441
  ]
385
442
  },
443
+ "pretty": {
444
+ "aliases": [],
445
+ "args": {
446
+ "spec-file": {
447
+ "description": "spec path, url, or context-name",
448
+ "name": "spec-file",
449
+ "required": true
450
+ }
451
+ },
452
+ "description": "Format AsyncAPI specification file",
453
+ "examples": [
454
+ "asyncapi pretty ./asyncapi.yaml",
455
+ "asyncapi pretty ./asyncapi.yaml --output formatted-asyncapi.yaml"
456
+ ],
457
+ "flags": {
458
+ "output": {
459
+ "char": "o",
460
+ "description": "Output file path",
461
+ "name": "output",
462
+ "hasDynamicHelp": false,
463
+ "multiple": false,
464
+ "type": "option"
465
+ }
466
+ },
467
+ "hasDynamicHelp": false,
468
+ "hiddenAliases": [],
469
+ "id": "pretty",
470
+ "pluginAlias": "@asyncapi/cli",
471
+ "pluginName": "@asyncapi/cli",
472
+ "pluginType": "core",
473
+ "strict": true,
474
+ "isESM": false,
475
+ "relativePath": [
476
+ "lib",
477
+ "commands",
478
+ "pretty.js"
479
+ ]
480
+ },
386
481
  "validate": {
387
482
  "aliases": [],
388
483
  "args": {
@@ -1637,5 +1732,5 @@
1637
1732
  ]
1638
1733
  }
1639
1734
  },
1640
- "version": "2.9.0"
1735
+ "version": "2.11.0"
1641
1736
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@asyncapi/cli",
3
3
  "description": "All in one CLI for all AsyncAPI tools",
4
- "version": "2.9.0",
4
+ "version": "2.11.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"
@@ -41,7 +41,8 @@
41
41
  "strip-ansi": "^6.0.0",
42
42
  "unzipper": "^0.10.11",
43
43
  "uuid": "^9.0.1",
44
- "ws": "^8.2.3"
44
+ "ws": "^8.2.3",
45
+ "yaml": "^2.6.1"
45
46
  },
46
47
  "devDependencies": {
47
48
  "@asyncapi/minimaltemplate": "./test/fixtures/minimaltemplate",