@asyncapi/cli 2.8.1 → 2.9.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.
@@ -5369,9 +5369,9 @@
5369
5369
  "peer": true
5370
5370
  },
5371
5371
  "node_modules/cookie": {
5372
- "version": "0.4.2",
5373
- "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
5374
- "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
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.5.5",
5912
- "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.5.tgz",
5913
- "integrity": "sha512-C5Pn8Wk+1vKBoHghJODM63yk8MvrO9EWZUfkAt5HAqIgPE4/8FF0PEGHXtEd40l223+cE5ABWuPzm38PHFXfMA==",
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.4.1",
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.7.5",
11798
- "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz",
11799
- "integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==",
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.5.2",
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.4.2",
5370
- "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
5371
- "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
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.5.5",
5909
- "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.5.tgz",
5910
- "integrity": "sha512-C5Pn8Wk+1vKBoHghJODM63yk8MvrO9EWZUfkAt5HAqIgPE4/8FF0PEGHXtEd40l223+cE5ABWuPzm38PHFXfMA==",
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.4.1",
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.7.5",
11795
- "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz",
11796
- "integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==",
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.5.2",
11802
+ "engine.io": "~6.6.0",
11803
11803
  "socket.io-adapter": "~2.5.2",
11804
11804
  "socket.io-parser": "~4.2.4"
11805
11805
  },
@@ -6,6 +6,7 @@ export default class Diff extends Command {
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
8
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "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>;
@@ -6,6 +6,7 @@ export default class Validate extends Command {
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
8
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "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
  };
@@ -2,6 +2,7 @@ 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
4
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "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>;
@@ -3,6 +3,7 @@ export declare const validateFlags: () => {
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
5
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "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
  };
@@ -16,11 +16,13 @@ export declare function validationFlags({ logDiagnostics }?: ValidationFlagsOpti
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
18
  'fail-severity': import("@oclif/core/lib/interfaces").OptionFlag<"error" | "warn" | "info" | "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<{
@@ -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
- if (diagnostics.length) {
74
- if (hasFailSeverity(diagnostics, failSeverity)) {
75
- if (logDiagnostics) {
76
- command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
77
- command.logToStderr(formatOutput(diagnostics, diagnosticsFormat, failSeverity));
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
- else if (logDiagnostics) {
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
- return ValidationStatus.VALID;
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
+ }
@@ -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,
@@ -437,6 +445,14 @@
437
445
  ],
438
446
  "type": "option"
439
447
  },
448
+ "output": {
449
+ "char": "o",
450
+ "description": "The output file name. Omitting this flag the result will be printed in the console.",
451
+ "name": "output",
452
+ "hasDynamicHelp": false,
453
+ "multiple": false,
454
+ "type": "option"
455
+ },
440
456
  "score": {
441
457
  "description": "Compute the score of the AsyncAPI document. Scoring is based on whether the document has description, license, server and/or channels.",
442
458
  "name": "score",
@@ -757,9 +773,8 @@
757
773
  },
758
774
  "output": {
759
775
  "char": "o",
760
- "description": "The output directory where the models should be written to. Omitting this flag will write the models to `stdout`.",
776
+ "description": "The output file name. Omitting this flag the result will be printed in the console.",
761
777
  "name": "output",
762
- "required": false,
763
778
  "hasDynamicHelp": false,
764
779
  "multiple": false,
765
780
  "type": "option"
@@ -1622,5 +1637,5 @@
1622
1637
  ]
1623
1638
  }
1624
1639
  },
1625
- "version": "2.8.1"
1640
+ "version": "2.9.0"
1626
1641
  }
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.8.1",
4
+ "version": "2.9.0",
5
5
  "author": "@asyncapi",
6
6
  "bin": {
7
7
  "asyncapi": "./bin/run_bin"