@asyncapi/cli 3.2.0 → 3.3.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-template/templates/default/package-lock.json +4 -3
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +89 -0
- package/lib/apps/api/configs/development.json +16 -0
- package/lib/apps/api/configs/production.json +16 -0
- package/lib/apps/api/configs/test.json +16 -0
- package/lib/apps/api/constants.d.ts +1 -0
- package/lib/apps/api/constants.js +4 -0
- package/lib/apps/api/controllers/bundle.controller.d.ts +7 -0
- package/lib/apps/api/controllers/bundle.controller.js +44 -0
- package/lib/apps/api/controllers/convert.controller.d.ts +11 -0
- package/lib/apps/api/controllers/convert.controller.js +69 -0
- package/lib/apps/api/controllers/diff.controller.d.ts +7 -0
- package/lib/apps/api/controllers/diff.controller.js +42 -0
- package/lib/apps/api/controllers/docs.controller.d.ts +6 -0
- package/lib/apps/api/controllers/docs.controller.js +24 -0
- package/lib/apps/api/controllers/generate.controller.d.ts +22 -0
- package/lib/apps/api/controllers/generate.controller.js +176 -0
- package/lib/apps/api/controllers/help.controller.d.ts +6 -0
- package/lib/apps/api/controllers/help.controller.js +101 -0
- package/lib/apps/api/controllers/parse.controller.d.ts +10 -0
- package/lib/apps/api/controllers/parse.controller.js +35 -0
- package/lib/apps/api/controllers/validate.controller.d.ts +10 -0
- package/lib/apps/api/controllers/validate.controller.js +50 -0
- package/lib/apps/api/exceptions/problem.exception.d.ts +14 -0
- package/lib/apps/api/exceptions/problem.exception.js +10 -0
- package/lib/apps/api/index.d.ts +9 -0
- package/lib/apps/api/index.js +21 -0
- package/lib/apps/api/middlewares/problem.middleware.d.ts +6 -0
- package/lib/apps/api/middlewares/problem.middleware.js +27 -0
- package/lib/apps/api/middlewares/validation.middleware.d.ts +12 -0
- package/lib/apps/api/middlewares/validation.middleware.js +236 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/{commands → apps/cli/commands}/bundle.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/bundle.js +3 -3
- package/lib/{commands → apps/cli/commands}/config/analytics.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/analytics.js +4 -3
- package/lib/{commands → apps/cli/commands}/config/context/add.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/add.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/current.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/current.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/edit.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/edit.js +12 -6
- package/lib/{commands → apps/cli/commands}/config/context/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/init.js +7 -4
- package/lib/{commands → apps/cli/commands}/config/context/list.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/list.js +4 -4
- package/lib/{commands → apps/cli/commands}/config/context/remove.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/remove.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/context/use.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/context/use.js +8 -5
- package/lib/{commands → apps/cli/commands}/config/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/config/versions.js +2 -2
- package/lib/{commands → apps/cli/commands}/convert.d.ts +2 -7
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/{commands → apps/cli/commands}/diff.d.ts +11 -2
- package/lib/{commands → apps/cli/commands}/diff.js +85 -31
- package/lib/{commands → apps/cli/commands}/format.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/format.js +4 -4
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.d.ts +4 -5
- package/lib/{commands → apps/cli/commands}/generate/fromTemplate.js +89 -122
- package/lib/{commands → apps/cli/commands}/generate/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/generate/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/generate/models.d.ts +6 -1
- package/lib/{commands → apps/cli/commands}/generate/models.js +48 -9
- package/lib/{commands → apps/cli/commands}/new/file.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/file.js +11 -8
- package/lib/{commands → apps/cli/commands}/new/glee.d.ts +2 -2
- package/lib/{commands → apps/cli/commands}/new/glee.js +4 -4
- package/lib/{commands → apps/cli/commands}/new/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/new/template.js +10 -8
- package/lib/{commands → apps/cli/commands}/optimize.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/optimize.js +71 -30
- package/lib/{commands → apps/cli/commands}/pretty.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/pretty.js +8 -5
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/{commands → apps/cli/commands}/start/index.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/index.js +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/preview.js +9 -6
- package/lib/{commands → apps/cli/commands}/start/studio.d.ts +1 -1
- package/lib/{commands → apps/cli/commands}/start/studio.js +10 -7
- package/lib/{commands → apps/cli/commands}/validate.d.ts +4 -2
- package/lib/apps/cli/commands/validate.js +94 -0
- package/lib/{core → apps/cli/internal}/base.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/base.js +12 -4
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/{core → apps/cli/internal}/flags/config/context.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/convert.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/diff.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/diff.flags.js +3 -3
- package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.js +12 -12
- package/lib/{core → apps/cli/internal}/flags/generate/models.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/flags/global.flags.js +1 -1
- package/lib/{core → apps/cli/internal}/flags/new/file.flags.js +7 -2
- package/lib/{core → apps/cli/internal}/flags/optimize.flags.js +24 -4
- package/lib/apps/cli/internal/flags/parser.flags.d.ts +10 -0
- package/lib/apps/cli/internal/flags/parser.flags.js +28 -0
- package/lib/{core → apps/cli/internal}/flags/proxy.flags.js +3 -3
- package/lib/apps/cli/internal/flags/start/api.flags.d.ts +5 -0
- package/lib/apps/cli/internal/flags/start/api.flags.js +20 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +31 -0
- package/lib/{core → apps/cli/internal}/flags/start/studio.flags.js +9 -2
- package/lib/{core → apps/cli/internal}/flags/validate.flags.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/flags/validate.flags.js +2 -2
- package/lib/{core → apps/cli/internal}/globals.d.ts +1 -1
- package/lib/{core → apps/cli/internal}/globals.js +2 -4
- package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.js +14 -4
- package/lib/{core → domains}/models/Context.js +1 -1
- package/lib/{core → domains}/models/Preview.js +35 -19
- package/lib/{core → domains}/models/SpecificationFile.d.ts +2 -2
- package/lib/{core → domains}/models/SpecificationFile.js +8 -5
- package/lib/{core → domains}/models/Studio.js +4 -4
- package/lib/domains/services/archiver.service.d.ts +17 -0
- package/lib/domains/services/archiver.service.js +53 -0
- package/lib/domains/services/base.service.d.ts +6 -0
- package/lib/domains/services/base.service.js +26 -0
- package/lib/domains/services/convert.service.d.ts +12 -0
- package/lib/domains/services/convert.service.js +65 -0
- package/lib/domains/services/generator.service.d.ts +15 -0
- package/lib/domains/services/generator.service.js +95 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +288 -0
- package/lib/{core/errors → errors}/specification-file.js +1 -1
- package/lib/{core/errors → errors}/validation-error.js +6 -5
- package/lib/interfaces/index.d.ts +87 -0
- package/lib/interfaces/index.js +7 -0
- package/lib/utils/ajv.d.ts +2 -0
- package/lib/utils/ajv.js +18 -0
- package/lib/utils/app-openapi.d.ts +4 -0
- package/lib/utils/app-openapi.js +28 -0
- package/lib/{core/utils/generator.js → utils/fileWatcher.js} +8 -2
- package/lib/utils/logger.d.ts +6 -0
- package/lib/utils/logger.js +33 -0
- package/lib/utils/retrieve-language.d.ts +1 -0
- package/lib/utils/retrieve-language.js +9 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +25 -0
- package/oclif.manifest.json +109 -1
- package/package.json +36 -10
- package/lib/commands/convert.js +0 -132
- package/lib/commands/validate.js +0 -47
- package/lib/core/flags/bundle.flags.js +0 -14
- package/lib/core/flags/config/analytics.flags.js +0 -13
- package/lib/core/flags/start/preview.flags.js +0 -15
- package/lib/core/parser.d.ts +0 -35
- package/lib/core/parser.js +0 -230
- /package/lib/{core → apps/cli/internal}/flags/bundle.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/analytics.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/config/context.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/convert.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/format.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/fromTemplate.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/generate/models.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/global.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/file.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/glee.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/new/template.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/optimize.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/pretty.flags.js +0 -0
- /package/lib/{core → apps/cli/internal}/flags/proxy.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/preview.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/flags/start/studio.flags.d.ts +0 -0
- /package/lib/{core → apps/cli/internal}/hooks/command_not_found/myhook.d.ts +0 -0
- /package/lib/{core → domains}/models/Context.d.ts +0 -0
- /package/lib/{core → domains}/models/Preview.d.ts +0 -0
- /package/lib/{core → domains}/models/Studio.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/context-error.js +0 -0
- /package/lib/{core/errors → errors}/diff-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/diff-error.js +0 -0
- /package/lib/{core/errors → errors}/generator-error.d.ts +0 -0
- /package/lib/{core/errors → errors}/generator-error.js +0 -0
- /package/lib/{core/errors → errors}/specification-file.d.ts +0 -0
- /package/lib/{core/errors → errors}/validation-error.d.ts +0 -0
- /package/lib/{core/utils/generator.d.ts → utils/fileWatcher.d.ts} +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.d.ts +0 -0
- /package/lib/{core/utils → utils}/scoreCalculator.js +0 -0
package/lib/core/parser.d.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { convertToOldAPI } from '@asyncapi/parser/cjs';
|
|
2
|
-
import { OutputFormat } from '@stoplight/spectral-cli/dist/services/config';
|
|
3
|
-
import type { Diagnostic } from '@asyncapi/parser/cjs';
|
|
4
|
-
import type Command from './base';
|
|
5
|
-
import type { Specification } from './models/SpecificationFile';
|
|
6
|
-
export type SeverityKind = 'error' | 'warn' | 'info' | 'hint';
|
|
7
|
-
export { convertToOldAPI };
|
|
8
|
-
export interface ValidationFlagsOptions {
|
|
9
|
-
logDiagnostics?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare enum ValidationStatus {
|
|
12
|
-
INVALID = "invalid",
|
|
13
|
-
VALID = "valid"
|
|
14
|
-
}
|
|
15
|
-
export declare function validationFlags({ logDiagnostics }?: ValidationFlagsOptions): {
|
|
16
|
-
'log-diagnostics': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
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<"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>;
|
|
20
|
-
};
|
|
21
|
-
export interface ValidateOptions {
|
|
22
|
-
'log-diagnostics'?: boolean;
|
|
23
|
-
'diagnostics-format'?: `${OutputFormat}`;
|
|
24
|
-
'fail-severity'?: SeverityKind;
|
|
25
|
-
'output'?: string;
|
|
26
|
-
suppressWarnings?: string[];
|
|
27
|
-
suppressAllWarnings?: boolean;
|
|
28
|
-
}
|
|
29
|
-
export declare function validate(command: Command, specFile: Specification, options?: ValidateOptions): Promise<"invalid" | "valid">;
|
|
30
|
-
export declare function parse(command: Command, specFile: Specification, options?: ValidateOptions): Promise<{
|
|
31
|
-
document: import("@asyncapi/parser/cjs").AsyncAPIDocumentInterface | undefined;
|
|
32
|
-
diagnostics: import("@stoplight/spectral-core").ISpectralDiagnostic[];
|
|
33
|
-
status: "invalid" | "valid";
|
|
34
|
-
}>;
|
|
35
|
-
export declare function formatOutput(diagnostics: Diagnostic[], format: `${OutputFormat}`, failSeverity: SeverityKind): string;
|
package/lib/core/parser.js
DELETED
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidationStatus = exports.convertToOldAPI = void 0;
|
|
4
|
-
exports.validationFlags = validationFlags;
|
|
5
|
-
exports.validate = validate;
|
|
6
|
-
exports.parse = parse;
|
|
7
|
-
exports.formatOutput = formatOutput;
|
|
8
|
-
const tslib_1 = require("tslib");
|
|
9
|
-
const avro_schema_parser_1 = require("@asyncapi/avro-schema-parser");
|
|
10
|
-
const openapi_schema_parser_1 = require("@asyncapi/openapi-schema-parser");
|
|
11
|
-
const cjs_1 = require("@asyncapi/parser/cjs");
|
|
12
|
-
Object.defineProperty(exports, "convertToOldAPI", { enumerable: true, get: function () { return cjs_1.convertToOldAPI; } });
|
|
13
|
-
const raml_dt_schema_parser_1 = require("@asyncapi/raml-dt-schema-parser");
|
|
14
|
-
const core_1 = require("@oclif/core");
|
|
15
|
-
const protobuf_schema_parser_1 = require("@asyncapi/protobuf-schema-parser");
|
|
16
|
-
const spectral_core_1 = require("@stoplight/spectral-core");
|
|
17
|
-
const config_1 = require("@stoplight/spectral-cli/dist/services/config");
|
|
18
|
-
const spectral_formatters_1 = require("@stoplight/spectral-formatters");
|
|
19
|
-
const chalk_1 = require("chalk");
|
|
20
|
-
const fs_1 = require("fs");
|
|
21
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
22
|
-
const { writeFile } = fs_1.promises;
|
|
23
|
-
const formatExtensions = {
|
|
24
|
-
stylish: '.txt',
|
|
25
|
-
json: '.json',
|
|
26
|
-
junit: '.xml',
|
|
27
|
-
html: '.html',
|
|
28
|
-
text: '.txt',
|
|
29
|
-
teamcity: '.txt',
|
|
30
|
-
pretty: '.txt',
|
|
31
|
-
};
|
|
32
|
-
const validFormats = ['stylish', 'json', 'junit', 'html', 'text', 'teamcity', 'pretty'];
|
|
33
|
-
const parser = new cjs_1.Parser({
|
|
34
|
-
__unstable: {
|
|
35
|
-
resolver: {
|
|
36
|
-
cache: false,
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
parser.registerSchemaParser((0, avro_schema_parser_1.AvroSchemaParser)());
|
|
41
|
-
parser.registerSchemaParser((0, openapi_schema_parser_1.OpenAPISchemaParser)());
|
|
42
|
-
parser.registerSchemaParser((0, raml_dt_schema_parser_1.RamlDTSchemaParser)());
|
|
43
|
-
parser.registerSchemaParser((0, protobuf_schema_parser_1.ProtoBuffSchemaParser)());
|
|
44
|
-
var ValidationStatus;
|
|
45
|
-
(function (ValidationStatus) {
|
|
46
|
-
ValidationStatus["INVALID"] = "invalid";
|
|
47
|
-
ValidationStatus["VALID"] = "valid";
|
|
48
|
-
})(ValidationStatus || (exports.ValidationStatus = ValidationStatus = {}));
|
|
49
|
-
function validationFlags({ logDiagnostics = true } = {}) {
|
|
50
|
-
return {
|
|
51
|
-
'log-diagnostics': core_1.Flags.boolean({
|
|
52
|
-
description: 'log validation diagnostics or not',
|
|
53
|
-
default: logDiagnostics,
|
|
54
|
-
allowNo: true,
|
|
55
|
-
}),
|
|
56
|
-
'diagnostics-format': core_1.Flags.option({
|
|
57
|
-
description: 'format to use for validation diagnostics',
|
|
58
|
-
options: Object.values(config_1.OutputFormat),
|
|
59
|
-
default: config_1.OutputFormat.STYLISH,
|
|
60
|
-
})(),
|
|
61
|
-
'fail-severity': core_1.Flags.option({
|
|
62
|
-
description: 'diagnostics of this level or above will trigger a failure exit code',
|
|
63
|
-
options: ['error', 'warn', 'info', 'hint'],
|
|
64
|
-
default: 'error',
|
|
65
|
-
})(),
|
|
66
|
-
output: core_1.Flags.string({
|
|
67
|
-
description: 'The output file name. Omitting this flag the result will be printed in the console.',
|
|
68
|
-
char: 'o'
|
|
69
|
-
})
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
function validate(command_1, specFile_1) {
|
|
73
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (command, specFile, options = {}) {
|
|
74
|
-
var _a, _b;
|
|
75
|
-
const suppressAllWarnings = (_a = options.suppressAllWarnings) !== null && _a !== void 0 ? _a : false;
|
|
76
|
-
const suppressedWarnings = (_b = options.suppressWarnings) !== null && _b !== void 0 ? _b : [];
|
|
77
|
-
let activeParser;
|
|
78
|
-
// Helper to build a parser with given rules turned off
|
|
79
|
-
const buildCustomParser = (rulesToSuppress) => new cjs_1.Parser({
|
|
80
|
-
ruleset: {
|
|
81
|
-
extends: [],
|
|
82
|
-
rules: Object.fromEntries(rulesToSuppress.map(rule => [rule, 'off'])),
|
|
83
|
-
},
|
|
84
|
-
__unstable: {
|
|
85
|
-
resolver: {
|
|
86
|
-
cache: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
if (suppressAllWarnings) {
|
|
91
|
-
// Run the default parser to discover all rule codes
|
|
92
|
-
const diagnostics = yield parser.validate(specFile.text(), {
|
|
93
|
-
source: specFile.getSource(),
|
|
94
|
-
});
|
|
95
|
-
const allRuleNames = Array.from(new Set(diagnostics.map(d => d.code).filter((c) => typeof c === 'string')));
|
|
96
|
-
activeParser = buildCustomParser(allRuleNames);
|
|
97
|
-
}
|
|
98
|
-
else if (suppressedWarnings.length === 0) {
|
|
99
|
-
activeParser = parser;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
try {
|
|
103
|
-
activeParser = buildCustomParser(suppressedWarnings);
|
|
104
|
-
}
|
|
105
|
-
catch (e) {
|
|
106
|
-
const msg = e.message || '';
|
|
107
|
-
const matches = [...msg.matchAll(/Cannot extend non-existing rule: "([^"]+)"/g)];
|
|
108
|
-
const invalidRules = matches.map(m => m[1]);
|
|
109
|
-
if (invalidRules.length > 0) {
|
|
110
|
-
for (const rule of invalidRules) {
|
|
111
|
-
command.log(`Warning: '${rule}' is not a known rule and will be ignored.`);
|
|
112
|
-
}
|
|
113
|
-
const validRules = suppressedWarnings.filter(rule => !invalidRules.includes(rule));
|
|
114
|
-
activeParser = buildCustomParser(validRules);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
throw e;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// Register schema parsers
|
|
122
|
-
activeParser.registerSchemaParser((0, avro_schema_parser_1.AvroSchemaParser)());
|
|
123
|
-
activeParser.registerSchemaParser((0, openapi_schema_parser_1.OpenAPISchemaParser)());
|
|
124
|
-
activeParser.registerSchemaParser((0, raml_dt_schema_parser_1.RamlDTSchemaParser)());
|
|
125
|
-
activeParser.registerSchemaParser((0, protobuf_schema_parser_1.ProtoBuffSchemaParser)());
|
|
126
|
-
const diagnostics = yield activeParser.validate(specFile.text(), {
|
|
127
|
-
source: specFile.getSource(),
|
|
128
|
-
});
|
|
129
|
-
return logDiagnostics(diagnostics, command, specFile, options);
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
function parse(command_1, specFile_1) {
|
|
133
|
-
return tslib_1.__awaiter(this, arguments, void 0, function* (command, specFile, options = {}) {
|
|
134
|
-
const { document, diagnostics } = yield parser.parse(specFile.text(), { source: specFile.getSource() });
|
|
135
|
-
const status = logDiagnostics(diagnostics, command, specFile, options);
|
|
136
|
-
return { document, diagnostics, status };
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
function logDiagnostics(diagnostics, command, specFile, options = {}) {
|
|
140
|
-
var _a, _b;
|
|
141
|
-
const logDiagnostics = options['log-diagnostics'];
|
|
142
|
-
const failSeverity = (_a = options['fail-severity']) !== null && _a !== void 0 ? _a : 'error';
|
|
143
|
-
const diagnosticsFormat = (_b = options['diagnostics-format']) !== null && _b !== void 0 ? _b : 'stylish';
|
|
144
|
-
const sourceString = specFile.toSourceString();
|
|
145
|
-
const hasIssues = diagnostics.length > 0;
|
|
146
|
-
const isFailSeverity = hasIssues && hasFailSeverity(diagnostics, failSeverity);
|
|
147
|
-
if (logDiagnostics) {
|
|
148
|
-
logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity);
|
|
149
|
-
outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options);
|
|
150
|
-
}
|
|
151
|
-
return isFailSeverity ? ValidationStatus.INVALID : ValidationStatus.VALID;
|
|
152
|
-
}
|
|
153
|
-
function logGovernanceMessage(command, sourceString, hasIssues, isFailSeverity) {
|
|
154
|
-
if (!hasIssues) {
|
|
155
|
-
command.log(`\n${sourceString} is valid! ${sourceString} and referenced documents don't have governance issues.`);
|
|
156
|
-
}
|
|
157
|
-
else if (isFailSeverity) {
|
|
158
|
-
command.logToStderr(`\n${sourceString} and/or referenced documents have governance issues.`);
|
|
159
|
-
}
|
|
160
|
-
else {
|
|
161
|
-
command.log(`\n${sourceString} is valid but has (itself and/or referenced documents) governance issues.`);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
function outputDiagnostics(command, diagnostics, diagnosticsFormat, failSeverity, options) {
|
|
165
|
-
const diagnosticsOutput = formatOutput(diagnostics, diagnosticsFormat, failSeverity);
|
|
166
|
-
if (options.output) {
|
|
167
|
-
writeValidationDiagnostic(options.output, command, diagnosticsFormat, diagnosticsOutput);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
command.log(diagnosticsOutput);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
function formatOutput(diagnostics, format, failSeverity) {
|
|
174
|
-
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
175
|
-
const options = { failSeverity: diagnosticSeverity !== -1 ? diagnosticSeverity : cjs_1.DiagnosticSeverity.Error };
|
|
176
|
-
switch (format) {
|
|
177
|
-
case 'stylish': return formatStylish(diagnostics, options);
|
|
178
|
-
case 'json': return (0, spectral_formatters_1.json)(diagnostics, options);
|
|
179
|
-
case 'junit': return (0, spectral_formatters_1.junit)(diagnostics, options);
|
|
180
|
-
case 'html': return (0, spectral_formatters_1.html)(diagnostics, options);
|
|
181
|
-
case 'text': return (0, spectral_formatters_1.text)(diagnostics, options);
|
|
182
|
-
case 'teamcity': return (0, spectral_formatters_1.teamcity)(diagnostics, options);
|
|
183
|
-
case 'pretty': return (0, spectral_formatters_1.pretty)(diagnostics, options);
|
|
184
|
-
default: return (0, spectral_formatters_1.stylish)(diagnostics, options);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function formatStylish(diagnostics, options) {
|
|
188
|
-
const groupedDiagnostics = diagnostics.reduce((acc, diagnostic) => {
|
|
189
|
-
const severity = diagnostic.severity;
|
|
190
|
-
if (!acc[severity]) {
|
|
191
|
-
acc[severity] = [];
|
|
192
|
-
}
|
|
193
|
-
acc[severity].push(diagnostic);
|
|
194
|
-
return acc;
|
|
195
|
-
}, {});
|
|
196
|
-
return Object.entries(groupedDiagnostics).map(([severity, diagnostics]) => {
|
|
197
|
-
return `${getSeverityTitle(Number(severity))} ${(0, spectral_formatters_1.stylish)(diagnostics, options)}`;
|
|
198
|
-
}).join('\n');
|
|
199
|
-
}
|
|
200
|
-
function getSeverityTitle(severity) {
|
|
201
|
-
switch (severity) {
|
|
202
|
-
case cjs_1.DiagnosticSeverity.Error: return (0, chalk_1.red)('Errors');
|
|
203
|
-
case cjs_1.DiagnosticSeverity.Warning: return (0, chalk_1.yellow)('Warnings');
|
|
204
|
-
case cjs_1.DiagnosticSeverity.Information: return (0, chalk_1.cyan)('Information');
|
|
205
|
-
case cjs_1.DiagnosticSeverity.Hint: return (0, chalk_1.green)('Hints');
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function hasFailSeverity(diagnostics, failSeverity) {
|
|
209
|
-
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
210
|
-
return diagnostics.some(diagnostic => diagnostic.severity <= diagnosticSeverity);
|
|
211
|
-
}
|
|
212
|
-
function writeValidationDiagnostic(outputPath, command, format, formatOutput) {
|
|
213
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
if (!validFormats.includes(format)) {
|
|
215
|
-
command.logToStderr(`Invalid diagnostics format: "${format}"`);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
const expectedExtension = formatExtensions[format];
|
|
219
|
-
const actualExtension = path_1.default.extname(outputPath);
|
|
220
|
-
// Validate file extension against diagnostics format
|
|
221
|
-
if (expectedExtension && (actualExtension !== expectedExtension)) {
|
|
222
|
-
command.logToStderr(`Invalid file extension for format "${format}". Expected extension: "${expectedExtension}"`);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
yield writeFile(path_1.default.resolve(process.cwd(), outputPath), formatOutput, {
|
|
226
|
-
encoding: 'utf-8',
|
|
227
|
-
}).catch(err => console.log(err));
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|