@asyncapi-actions-test/trusted-publishing-test_asyncapi-cli 4.1.3
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/LICENSE +201 -0
- package/README.md +117 -0
- package/assets/create-template/templates/default/asyncapi.yaml +34 -0
- package/assets/create-template/templates/default/package-lock.json +4062 -0
- package/assets/create-template/templates/default/package.json +10 -0
- package/assets/create-template/templates/default/readme.md +4 -0
- package/assets/create-template/templates/default/template/index.js +11 -0
- package/assets/examples/adeo-kafka-request-reply-asyncapi.yml +298 -0
- package/assets/examples/anyof-asyncapi.yml +36 -0
- package/assets/examples/application-headers-asyncapi.yml +86 -0
- package/assets/examples/correlation-id-asyncapi.yml +180 -0
- package/assets/examples/default-example.json +51 -0
- package/assets/examples/default-example.yaml +31 -0
- package/assets/examples/examples.json +82 -0
- package/assets/examples/gitter-streaming-asyncapi.yml +178 -0
- package/assets/examples/kraken-websocket-request-reply-message-filter-in-reply-asyncapi.yml +388 -0
- package/assets/examples/kraken-websocket-request-reply-multiple-channels-asyncapi.yml +394 -0
- package/assets/examples/mercure-asyncapi.yml +58 -0
- package/assets/examples/not-asyncapi.yml +29 -0
- package/assets/examples/oneof-asyncapi.yml +57 -0
- package/assets/examples/operation-security-asyncapi.yml +117 -0
- package/assets/examples/rpc-client-asyncapi.yml +72 -0
- package/assets/examples/rpc-server-asyncapi.yml +69 -0
- package/assets/examples/simple-asyncapi.yml +31 -0
- package/assets/examples/slack-rtm-asyncapi.yml +982 -0
- package/assets/examples/streetlights-kafka-asyncapi.yml +199 -0
- package/assets/examples/streetlights-mqtt-asyncapi.yml +253 -0
- package/assets/examples/streetlights-operation-security-asyncapi.yml +240 -0
- package/assets/examples/tutorial.yml +41 -0
- package/assets/examples/websocket-gemini-asyncapi.yml +301 -0
- package/assets/logo.png +0 -0
- package/assets/server-api.png +0 -0
- package/bin/dev +17 -0
- package/bin/dev.cmd +3 -0
- package/bin/run +12 -0
- package/bin/run.cmd +3 -0
- package/bin/run_bin +13 -0
- package/bin/run_bin.cmd +3 -0
- package/lib/apps/api/app.d.ts +15 -0
- package/lib/apps/api/app.js +91 -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 +174 -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/controllers/version.controller.d.ts +8 -0
- package/lib/apps/api/controllers/version.controller.js +69 -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 +10 -0
- package/lib/apps/api/index.js +23 -0
- package/lib/apps/api/middlewares/logger.middleware.d.ts +2 -0
- package/lib/apps/api/middlewares/logger.middleware.js +12 -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 +245 -0
- package/lib/apps/api/server.d.ts +3 -0
- package/lib/apps/api/server.js +19 -0
- package/lib/apps/cli/commands/bundle.d.ts +15 -0
- package/lib/apps/cli/commands/bundle.js +75 -0
- package/lib/apps/cli/commands/config/analytics.d.ts +11 -0
- package/lib/apps/cli/commands/config/analytics.js +61 -0
- package/lib/apps/cli/commands/config/auth/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/auth/add.js +68 -0
- package/lib/apps/cli/commands/config/context/add.d.ts +13 -0
- package/lib/apps/cli/commands/config/context/add.js +46 -0
- package/lib/apps/cli/commands/config/context/current.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/current.js +37 -0
- package/lib/apps/cli/commands/config/context/edit.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/edit.js +44 -0
- package/lib/apps/cli/commands/config/context/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/context/index.js +16 -0
- package/lib/apps/cli/commands/config/context/init.d.ts +12 -0
- package/lib/apps/cli/commands/config/context/init.js +31 -0
- package/lib/apps/cli/commands/config/context/list.d.ts +8 -0
- package/lib/apps/cli/commands/config/context/list.js +36 -0
- package/lib/apps/cli/commands/config/context/remove.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/remove.js +39 -0
- package/lib/apps/cli/commands/config/context/use.d.ts +11 -0
- package/lib/apps/cli/commands/config/context/use.js +40 -0
- package/lib/apps/cli/commands/config/index.d.ts +5 -0
- package/lib/apps/cli/commands/config/index.js +16 -0
- package/lib/apps/cli/commands/config/versions.d.ts +8 -0
- package/lib/apps/cli/commands/config/versions.js +56 -0
- package/lib/apps/cli/commands/convert.d.ts +21 -0
- package/lib/apps/cli/commands/convert.js +85 -0
- package/lib/apps/cli/commands/diff.d.ts +36 -0
- package/lib/apps/cli/commands/diff.js +335 -0
- package/lib/apps/cli/commands/format.d.ts +18 -0
- package/lib/apps/cli/commands/format.js +97 -0
- package/lib/apps/cli/commands/generate/client.d.ts +30 -0
- package/lib/apps/cli/commands/generate/client.js +94 -0
- package/lib/apps/cli/commands/generate/fromTemplate.d.ts +29 -0
- package/lib/apps/cli/commands/generate/fromTemplate.js +91 -0
- package/lib/apps/cli/commands/generate/index.d.ts +5 -0
- package/lib/apps/cli/commands/generate/index.js +15 -0
- package/lib/apps/cli/commands/generate/models.d.ts +16 -0
- package/lib/apps/cli/commands/generate/models.js +166 -0
- package/lib/apps/cli/commands/new/file.d.ts +16 -0
- package/lib/apps/cli/commands/new/file.js +180 -0
- package/lib/apps/cli/commands/new/index.d.ts +5 -0
- package/lib/apps/cli/commands/new/index.js +15 -0
- package/lib/apps/cli/commands/new/template.d.ts +18 -0
- package/lib/apps/cli/commands/new/template.js +102 -0
- package/lib/apps/cli/commands/optimize.d.ts +41 -0
- package/lib/apps/cli/commands/optimize.js +289 -0
- package/lib/apps/cli/commands/pretty.d.ts +12 -0
- package/lib/apps/cli/commands/pretty.js +70 -0
- package/lib/apps/cli/commands/start/api.d.ts +11 -0
- package/lib/apps/cli/commands/start/api.js +23 -0
- package/lib/apps/cli/commands/start/index.d.ts +5 -0
- package/lib/apps/cli/commands/start/index.js +15 -0
- package/lib/apps/cli/commands/start/preview.d.ts +17 -0
- package/lib/apps/cli/commands/start/preview.js +41 -0
- package/lib/apps/cli/commands/start/studio.d.ts +16 -0
- package/lib/apps/cli/commands/start/studio.js +94 -0
- package/lib/apps/cli/commands/validate.d.ts +23 -0
- package/lib/apps/cli/commands/validate.js +95 -0
- package/lib/apps/cli/internal/args/generate.args.d.ts +3 -0
- package/lib/apps/cli/internal/args/generate.args.js +10 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.d.ts +42 -0
- package/lib/apps/cli/internal/base/BaseGeneratorCommand.js +119 -0
- package/lib/apps/cli/internal/base.d.ts +20 -0
- package/lib/apps/cli/internal/base.js +173 -0
- package/lib/apps/cli/internal/flags/bundle.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/bundle.flags.js +26 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/config/analytics.flags.js +24 -0
- package/lib/apps/cli/internal/flags/config/context.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/config/context.flags.js +16 -0
- package/lib/apps/cli/internal/flags/convert.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/convert.flags.js +32 -0
- package/lib/apps/cli/internal/flags/diff.flags.d.ts +13 -0
- package/lib/apps/cli/internal/flags/diff.flags.js +29 -0
- package/lib/apps/cli/internal/flags/format.flags.d.ts +6 -0
- package/lib/apps/cli/internal/flags/format.flags.js +22 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/clients.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/fromTemplate.flags.js +8 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.d.ts +1 -0
- package/lib/apps/cli/internal/flags/generate/models.flags.js +14 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.d.ts +16 -0
- package/lib/apps/cli/internal/flags/generate/sharedFlags.js +57 -0
- package/lib/apps/cli/internal/flags/global.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/global.flags.js +18 -0
- package/lib/apps/cli/internal/flags/new/file.flags.d.ts +8 -0
- package/lib/apps/cli/internal/flags/new/file.flags.js +20 -0
- package/lib/apps/cli/internal/flags/new/template.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/new/template.flags.js +28 -0
- package/lib/apps/cli/internal/flags/optimize.flags.d.ts +21 -0
- package/lib/apps/cli/internal/flags/optimize.flags.js +51 -0
- 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/apps/cli/internal/flags/pretty.flags.d.ts +3 -0
- package/lib/apps/cli/internal/flags/pretty.flags.js +13 -0
- package/lib/apps/cli/internal/flags/proxy.flags.d.ts +4 -0
- package/lib/apps/cli/internal/flags/proxy.flags.js +17 -0
- 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.d.ts +9 -0
- package/lib/apps/cli/internal/flags/start/preview.flags.js +32 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.d.ts +7 -0
- package/lib/apps/cli/internal/flags/start/studio.flags.js +25 -0
- package/lib/apps/cli/internal/flags/validate.flags.d.ts +11 -0
- package/lib/apps/cli/internal/flags/validate.flags.js +22 -0
- package/lib/apps/cli/internal/globals.d.ts +10 -0
- package/lib/apps/cli/internal/globals.js +46 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.d.ts +4 -0
- package/lib/apps/cli/internal/hooks/command_not_found/myhook.js +85 -0
- package/lib/domains/models/Context.d.ts +21 -0
- package/lib/domains/models/Context.js +321 -0
- package/lib/domains/models/Preview.d.ts +2 -0
- package/lib/domains/models/Preview.js +227 -0
- package/lib/domains/models/SpecificationFile.d.ts +40 -0
- package/lib/domains/models/SpecificationFile.js +295 -0
- package/lib/domains/models/Studio.d.ts +2 -0
- package/lib/domains/models/Studio.js +182 -0
- package/lib/domains/models/generate/ClientLanguages.d.ts +12 -0
- package/lib/domains/models/generate/ClientLanguages.js +17 -0
- package/lib/domains/models/generate/Flags.d.ts +9 -0
- package/lib/domains/models/generate/Flags.js +2 -0
- 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/config.service.d.ts +42 -0
- package/lib/domains/services/config.service.js +95 -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 +75 -0
- package/lib/domains/services/validation.service.d.ts +54 -0
- package/lib/domains/services/validation.service.js +375 -0
- package/lib/errors/context-error.d.ts +26 -0
- package/lib/errors/context-error.js +71 -0
- package/lib/errors/diff-error.d.ts +9 -0
- package/lib/errors/diff-error.js +27 -0
- package/lib/errors/generator-error.d.ts +3 -0
- package/lib/errors/generator-error.js +11 -0
- package/lib/errors/specification-file.d.ts +18 -0
- package/lib/errors/specification-file.js +65 -0
- package/lib/errors/validation-error.d.ts +11 -0
- package/lib/errors/validation-error.js +55 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -0
- 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/utils/generate/flags.d.ts +2 -0
- package/lib/utils/generate/flags.js +14 -0
- package/lib/utils/generate/mapBaseUrl.d.ts +6 -0
- package/lib/utils/generate/mapBaseUrl.js +34 -0
- package/lib/utils/generate/parseParams.d.ts +3 -0
- package/lib/utils/generate/parseParams.js +58 -0
- package/lib/utils/generate/prompts.d.ts +4 -0
- package/lib/utils/generate/prompts.js +77 -0
- package/lib/utils/generate/registry.d.ts +2 -0
- package/lib/utils/generate/registry.js +30 -0
- package/lib/utils/generate/watcher.d.ts +51 -0
- package/lib/utils/generate/watcher.js +230 -0
- 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/scoreCalculator.d.ts +2 -0
- package/lib/utils/scoreCalculator.js +22 -0
- package/lib/utils/temp-dir.d.ts +2 -0
- package/lib/utils/temp-dir.js +26 -0
- package/oclif.manifest.json +2137 -0
- package/openapi.yaml +713 -0
- package/package.json +203 -0
- package/scripts/enableAutoComplete.js +160 -0
- package/scripts/fetch-asyncapi-example.js +126 -0
- package/scripts/generateTypesForGenerateCommand.js +40 -0
- package/scripts/releasePackagesRename.js +88 -0
- package/scripts/updateUsageDocs.js +73 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseService } from './base.service';
|
|
2
|
+
import { ValidationOptions, ValidationResult, ServiceResult, ParsedDocument, DiagnosticsFormat, SeverityKind } from '../../interfaces';
|
|
3
|
+
import type { Diagnostic } from '@asyncapi/parser/cjs';
|
|
4
|
+
import { Specification } from '../models/SpecificationFile';
|
|
5
|
+
import { ParseOptions } from '@asyncapi/parser';
|
|
6
|
+
import { ParserOptions } from '@asyncapi/parser/cjs/parser';
|
|
7
|
+
export declare enum ValidationStatus {
|
|
8
|
+
INVALID = "invalid",
|
|
9
|
+
VALID = "valid"
|
|
10
|
+
}
|
|
11
|
+
export declare class ValidationService extends BaseService {
|
|
12
|
+
private parser;
|
|
13
|
+
constructor(parserOptions?: ParserOptions);
|
|
14
|
+
/**
|
|
15
|
+
* Determine validation status from diagnostics
|
|
16
|
+
*/
|
|
17
|
+
private determineDiagnosticsStatus;
|
|
18
|
+
/**
|
|
19
|
+
* Parses an AsyncAPI document and returns the parsed result
|
|
20
|
+
*/
|
|
21
|
+
parseDocument(specFile: Specification, parseOptions?: ParseOptions, options?: ValidationOptions): Promise<ServiceResult<ParsedDocument>>;
|
|
22
|
+
/**
|
|
23
|
+
* Validates an AsyncAPI document
|
|
24
|
+
*/
|
|
25
|
+
validateDocument(specFile: Specification, options?: ValidationOptions): Promise<ServiceResult<ValidationResult>>;
|
|
26
|
+
/**
|
|
27
|
+
* Helper to build and register a custom parser with suppressed rules
|
|
28
|
+
*/
|
|
29
|
+
private buildAndRegisterCustomParser;
|
|
30
|
+
/**
|
|
31
|
+
* Save validation diagnostics to file
|
|
32
|
+
*/
|
|
33
|
+
saveDiagnosticsToFile(outputPath: string, format: DiagnosticsFormat, formatOutput: string): Promise<ServiceResult<string>>;
|
|
34
|
+
/**
|
|
35
|
+
* Generate governance message based on validation results
|
|
36
|
+
*/
|
|
37
|
+
generateGovernanceMessage(sourceString: string, hasIssues: boolean, isFailSeverity: boolean): string;
|
|
38
|
+
/**
|
|
39
|
+
* Check if diagnostics contain failure severity issues
|
|
40
|
+
*/
|
|
41
|
+
private hasFailSeverity;
|
|
42
|
+
/**
|
|
43
|
+
* Format validation diagnostics output
|
|
44
|
+
*/
|
|
45
|
+
formatDiagnosticsOutput(diagnostics: Diagnostic[], format?: DiagnosticsFormat, failSeverity?: SeverityKind): string;
|
|
46
|
+
/**
|
|
47
|
+
* Format diagnostics in stylish format with severity grouping
|
|
48
|
+
*/
|
|
49
|
+
private formatStylish;
|
|
50
|
+
/**
|
|
51
|
+
* Get colored severity title
|
|
52
|
+
*/
|
|
53
|
+
private getSeverityTitle;
|
|
54
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ValidationService = exports.ValidationStatus = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const base_service_1 = require("./base.service");
|
|
6
|
+
const avro_schema_parser_1 = require("@asyncapi/avro-schema-parser");
|
|
7
|
+
const openapi_schema_parser_1 = require("@asyncapi/openapi-schema-parser");
|
|
8
|
+
const cjs_1 = require("@asyncapi/parser/cjs");
|
|
9
|
+
const raml_dt_schema_parser_1 = require("@asyncapi/raml-dt-schema-parser");
|
|
10
|
+
const protobuf_schema_parser_1 = require("@asyncapi/protobuf-schema-parser");
|
|
11
|
+
const spectral_core_1 = require("@stoplight/spectral-core");
|
|
12
|
+
const spectral_formatters_1 = require("@stoplight/spectral-formatters");
|
|
13
|
+
const chalk_1 = require("chalk");
|
|
14
|
+
const fs_1 = require("fs");
|
|
15
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
16
|
+
const scoreCalculator_1 = require("../../utils/scoreCalculator");
|
|
17
|
+
const config_service_1 = require("./config.service");
|
|
18
|
+
/**
|
|
19
|
+
* Helper function to validate if a URL is a GitHub blob URL
|
|
20
|
+
*/
|
|
21
|
+
const isValidGitHubBlobUrl = (url) => {
|
|
22
|
+
try {
|
|
23
|
+
const parsedUrl = new URL(url);
|
|
24
|
+
return (parsedUrl.hostname === 'github.com' &&
|
|
25
|
+
parsedUrl.pathname.split('/')[3] === 'blob');
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Convert GitHub web URL to API URL
|
|
33
|
+
*/
|
|
34
|
+
const convertGitHubWebUrl = (url) => {
|
|
35
|
+
// Remove fragment from URL before processing
|
|
36
|
+
const urlWithoutFragment = url.split('#')[0];
|
|
37
|
+
// Handle GitHub web URLs like: https://github.com/owner/repo/blob/branch/path
|
|
38
|
+
// eslint-disable-next-line no-useless-escape
|
|
39
|
+
const githubWebPattern = /^https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+)$/;
|
|
40
|
+
const match = urlWithoutFragment.match(githubWebPattern);
|
|
41
|
+
if (match) {
|
|
42
|
+
const [, owner, repo, branch, filePath] = match;
|
|
43
|
+
return `https://api.github.com/repos/${owner}/${repo}/contents/${filePath}?ref=${branch}`;
|
|
44
|
+
}
|
|
45
|
+
return url;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Custom resolver for private repositories
|
|
49
|
+
*/
|
|
50
|
+
const createHttpWithAuthResolver = () => ({
|
|
51
|
+
schema: 'https',
|
|
52
|
+
order: 1,
|
|
53
|
+
read: (uri) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
+
let url = uri.toString();
|
|
55
|
+
// Default headers
|
|
56
|
+
const headers = {
|
|
57
|
+
'User-Agent': 'AsyncAPI-CLI',
|
|
58
|
+
};
|
|
59
|
+
const authInfo = yield config_service_1.ConfigService.getAuthForUrl(url);
|
|
60
|
+
if (isValidGitHubBlobUrl(url)) {
|
|
61
|
+
url = convertGitHubWebUrl(url);
|
|
62
|
+
}
|
|
63
|
+
if (authInfo) {
|
|
64
|
+
headers['Authorization'] = `${authInfo.authType} ${authInfo.token}`;
|
|
65
|
+
Object.assign(headers, authInfo.headers); // merge custom headers
|
|
66
|
+
}
|
|
67
|
+
if (url.includes('api.github.com')) {
|
|
68
|
+
headers['Accept'] = 'application/vnd.github.v3+json';
|
|
69
|
+
const res = yield fetch(url, { headers });
|
|
70
|
+
if (!res.ok) {
|
|
71
|
+
throw new Error(`Failed to fetch GitHub API URL: ${url} - ${res.statusText}`);
|
|
72
|
+
}
|
|
73
|
+
const fileInfo = (yield res.json());
|
|
74
|
+
if (fileInfo.download_url) {
|
|
75
|
+
const contentRes = yield fetch(fileInfo.download_url, { headers });
|
|
76
|
+
if (!contentRes.ok) {
|
|
77
|
+
throw new Error(`Failed to fetch content from download URL: ${fileInfo.download_url} - ${contentRes.statusText}`);
|
|
78
|
+
}
|
|
79
|
+
return yield contentRes.text();
|
|
80
|
+
}
|
|
81
|
+
throw new Error(`No download URL found in GitHub API response for: ${url}`);
|
|
82
|
+
}
|
|
83
|
+
else if (url.includes('raw.githubusercontent.com')) {
|
|
84
|
+
headers['Accept'] = 'application/vnd.github.v3.raw';
|
|
85
|
+
const res = yield fetch(url, { headers });
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
throw new Error(`Failed to fetch GitHub URL: ${url} - ${res.statusText}`);
|
|
88
|
+
}
|
|
89
|
+
return yield res.text();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
const res = yield fetch(url, { headers });
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
throw new Error(`Failed to fetch URL: ${url} - ${res.statusText}`);
|
|
95
|
+
}
|
|
96
|
+
return yield res.text();
|
|
97
|
+
}
|
|
98
|
+
}),
|
|
99
|
+
});
|
|
100
|
+
const { writeFile } = fs_1.promises;
|
|
101
|
+
var ValidationStatus;
|
|
102
|
+
(function (ValidationStatus) {
|
|
103
|
+
ValidationStatus["INVALID"] = "invalid";
|
|
104
|
+
ValidationStatus["VALID"] = "valid";
|
|
105
|
+
})(ValidationStatus || (exports.ValidationStatus = ValidationStatus = {}));
|
|
106
|
+
const formatExtensions = {
|
|
107
|
+
stylish: '.txt',
|
|
108
|
+
json: '.json',
|
|
109
|
+
junit: '.xml',
|
|
110
|
+
html: '.html',
|
|
111
|
+
text: '.txt',
|
|
112
|
+
teamcity: '.txt',
|
|
113
|
+
pretty: '.txt',
|
|
114
|
+
};
|
|
115
|
+
const validFormats = [
|
|
116
|
+
'stylish',
|
|
117
|
+
'json',
|
|
118
|
+
'junit',
|
|
119
|
+
'html',
|
|
120
|
+
'text',
|
|
121
|
+
'teamcity',
|
|
122
|
+
'pretty',
|
|
123
|
+
];
|
|
124
|
+
class ValidationService extends base_service_1.BaseService {
|
|
125
|
+
constructor(parserOptions = {}) {
|
|
126
|
+
var _a, _b, _c;
|
|
127
|
+
super();
|
|
128
|
+
// Create parser with custom GitHub resolver
|
|
129
|
+
const customParserOptions = Object.assign(Object.assign({}, parserOptions), { __unstable: Object.assign(Object.assign({}, parserOptions.__unstable), { resolver: Object.assign(Object.assign({}, (_a = parserOptions.__unstable) === null || _a === void 0 ? void 0 : _a.resolver), { cache: false, resolvers: [
|
|
130
|
+
createHttpWithAuthResolver(),
|
|
131
|
+
...(((_c = (_b = parserOptions.__unstable) === null || _b === void 0 ? void 0 : _b.resolver) === null || _c === void 0 ? void 0 : _c.resolvers) || [])
|
|
132
|
+
] }) }) });
|
|
133
|
+
this.parser = new cjs_1.Parser(customParserOptions);
|
|
134
|
+
this.parser.registerSchemaParser((0, openapi_schema_parser_1.OpenAPISchemaParser)());
|
|
135
|
+
this.parser.registerSchemaParser((0, raml_dt_schema_parser_1.RamlDTSchemaParser)());
|
|
136
|
+
this.parser.registerSchemaParser((0, avro_schema_parser_1.AvroSchemaParser)());
|
|
137
|
+
this.parser.registerSchemaParser((0, protobuf_schema_parser_1.ProtoBuffSchemaParser)());
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Determine validation status from diagnostics
|
|
141
|
+
*/
|
|
142
|
+
determineDiagnosticsStatus(diagnostics, options) {
|
|
143
|
+
var _a;
|
|
144
|
+
const failSeverity = (_a = options['fail-severity']) !== null && _a !== void 0 ? _a : 'error';
|
|
145
|
+
const hasIssues = diagnostics.length > 0;
|
|
146
|
+
const isFailSeverity = hasIssues && this.hasFailSeverity(diagnostics, failSeverity);
|
|
147
|
+
return isFailSeverity ? ValidationStatus.INVALID : ValidationStatus.VALID;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Parses an AsyncAPI document and returns the parsed result
|
|
151
|
+
*/
|
|
152
|
+
parseDocument(specFile_1, parseOptions_1) {
|
|
153
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (specFile, parseOptions, options = {}) {
|
|
154
|
+
try {
|
|
155
|
+
const { document, diagnostics } = yield this.parser.parse(specFile.text(), Object.assign({ source: specFile.getSource() }, parseOptions));
|
|
156
|
+
if (!document) {
|
|
157
|
+
return this.createErrorResult('Failed to parse document');
|
|
158
|
+
}
|
|
159
|
+
const status = this.determineDiagnosticsStatus(diagnostics, options);
|
|
160
|
+
const result = {
|
|
161
|
+
document,
|
|
162
|
+
diagnostics,
|
|
163
|
+
status: status,
|
|
164
|
+
};
|
|
165
|
+
return this.createSuccessResult(result);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
return this.handleServiceError(error);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Validates an AsyncAPI document
|
|
174
|
+
*/
|
|
175
|
+
validateDocument(specFile_1) {
|
|
176
|
+
return tslib_1.__awaiter(this, arguments, void 0, function* (specFile, options = {}) {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
try {
|
|
179
|
+
const suppressAllWarnings = (_a = options.suppressAllWarnings) !== null && _a !== void 0 ? _a : false;
|
|
180
|
+
const suppressedWarnings = (_b = options.suppressWarnings) !== null && _b !== void 0 ? _b : [];
|
|
181
|
+
let activeParser;
|
|
182
|
+
if (suppressAllWarnings || suppressedWarnings.length) {
|
|
183
|
+
activeParser = yield this.buildAndRegisterCustomParser(specFile, suppressedWarnings, suppressAllWarnings);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
activeParser = this.parser;
|
|
187
|
+
}
|
|
188
|
+
const { document, diagnostics } = yield activeParser.parse(specFile.text(), {
|
|
189
|
+
source: specFile.getSource(),
|
|
190
|
+
});
|
|
191
|
+
const status = this.determineDiagnosticsStatus(diagnostics, options);
|
|
192
|
+
const result = {
|
|
193
|
+
status: status,
|
|
194
|
+
diagnostics,
|
|
195
|
+
score: yield (0, scoreCalculator_1.calculateScore)(document),
|
|
196
|
+
document: (document === null || document === void 0 ? void 0 : document.json) ? document.json() : undefined,
|
|
197
|
+
};
|
|
198
|
+
return this.createSuccessResult(result);
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
return this.handleServiceError(error);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Helper to build and register a custom parser with suppressed rules
|
|
207
|
+
*/
|
|
208
|
+
buildAndRegisterCustomParser(specFile, suppressedWarnings, suppressAllWarnings) {
|
|
209
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
// Helper to build a parser with given rules turned off
|
|
211
|
+
const buildCustomParser = (rulesToSuppress) => new cjs_1.Parser({
|
|
212
|
+
ruleset: {
|
|
213
|
+
extends: [],
|
|
214
|
+
rules: Object.fromEntries(rulesToSuppress.map((rule) => [rule, 'off'])),
|
|
215
|
+
},
|
|
216
|
+
__unstable: {
|
|
217
|
+
resolver: {
|
|
218
|
+
cache: false,
|
|
219
|
+
resolvers: [createHttpWithAuthResolver()],
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
let activeParser;
|
|
224
|
+
if (suppressAllWarnings || suppressedWarnings.length) {
|
|
225
|
+
if (suppressAllWarnings) {
|
|
226
|
+
// Run the default parser to discover all rule codes
|
|
227
|
+
const diagnostics = yield this.parser.validate(specFile.text(), {
|
|
228
|
+
source: specFile.getSource(),
|
|
229
|
+
});
|
|
230
|
+
const allRuleNames = Array.from(new Set(diagnostics
|
|
231
|
+
.map((d) => d.code)
|
|
232
|
+
.filter((c) => typeof c === 'string')));
|
|
233
|
+
activeParser = buildCustomParser(allRuleNames);
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
try {
|
|
237
|
+
activeParser = buildCustomParser(suppressedWarnings);
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
const msg = e.message || '';
|
|
241
|
+
const matches = [
|
|
242
|
+
...msg.matchAll(/Cannot extend non-existing rule: "([^"]+)"/g),
|
|
243
|
+
];
|
|
244
|
+
const invalidRules = matches.map((m) => m[1]);
|
|
245
|
+
if (invalidRules.length > 0) {
|
|
246
|
+
const validRules = suppressedWarnings.filter((rule) => !invalidRules.includes(rule));
|
|
247
|
+
activeParser = buildCustomParser(validRules);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
throw e;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Register schema parsers for active parser
|
|
255
|
+
activeParser.registerSchemaParser((0, avro_schema_parser_1.AvroSchemaParser)());
|
|
256
|
+
activeParser.registerSchemaParser((0, openapi_schema_parser_1.OpenAPISchemaParser)());
|
|
257
|
+
activeParser.registerSchemaParser((0, raml_dt_schema_parser_1.RamlDTSchemaParser)());
|
|
258
|
+
activeParser.registerSchemaParser((0, protobuf_schema_parser_1.ProtoBuffSchemaParser)());
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
throw new Error('No rules to suppress provided');
|
|
262
|
+
}
|
|
263
|
+
return activeParser;
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Save validation diagnostics to file
|
|
268
|
+
*/
|
|
269
|
+
saveDiagnosticsToFile(outputPath, format, formatOutput) {
|
|
270
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
271
|
+
try {
|
|
272
|
+
if (!validFormats.includes(format)) {
|
|
273
|
+
return this.createErrorResult(`Invalid diagnostics format: "${format}"`);
|
|
274
|
+
}
|
|
275
|
+
const expectedExtension = formatExtensions[format];
|
|
276
|
+
const actualExtension = path_1.default.extname(outputPath);
|
|
277
|
+
// Validate file extension against diagnostics format
|
|
278
|
+
if (expectedExtension && actualExtension !== expectedExtension) {
|
|
279
|
+
return this.createErrorResult(`Invalid file extension for format "${format}". Expected extension: "${expectedExtension}"`);
|
|
280
|
+
}
|
|
281
|
+
yield writeFile(path_1.default.resolve(process.cwd(), outputPath), formatOutput, {
|
|
282
|
+
encoding: 'utf-8',
|
|
283
|
+
});
|
|
284
|
+
return this.createSuccessResult(outputPath);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
return this.handleServiceError(error);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Generate governance message based on validation results
|
|
293
|
+
*/
|
|
294
|
+
generateGovernanceMessage(sourceString, hasIssues, isFailSeverity) {
|
|
295
|
+
if (!hasIssues) {
|
|
296
|
+
return `\n${sourceString} is valid! ${sourceString} and referenced documents don't have governance issues.`;
|
|
297
|
+
}
|
|
298
|
+
if (isFailSeverity) {
|
|
299
|
+
return `\n${sourceString} and/or referenced documents have governance issues.`;
|
|
300
|
+
}
|
|
301
|
+
return `\n${sourceString} is valid but has (itself and/or referenced documents) governance issues.`;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Check if diagnostics contain failure severity issues
|
|
305
|
+
*/
|
|
306
|
+
hasFailSeverity(diagnostics, failSeverity) {
|
|
307
|
+
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
308
|
+
return diagnostics.some((diagnostic) => diagnostic.severity <= diagnosticSeverity);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Format validation diagnostics output
|
|
312
|
+
*/
|
|
313
|
+
formatDiagnosticsOutput(diagnostics, format = 'stylish', failSeverity = 'error') {
|
|
314
|
+
const diagnosticSeverity = (0, spectral_core_1.getDiagnosticSeverity)(failSeverity);
|
|
315
|
+
const options = {
|
|
316
|
+
failSeverity: diagnosticSeverity !== -1
|
|
317
|
+
? diagnosticSeverity
|
|
318
|
+
: cjs_1.DiagnosticSeverity.Error,
|
|
319
|
+
};
|
|
320
|
+
switch (format) {
|
|
321
|
+
case 'stylish':
|
|
322
|
+
return this.formatStylish(diagnostics, options);
|
|
323
|
+
case 'json':
|
|
324
|
+
return (0, spectral_formatters_1.json)(diagnostics, options);
|
|
325
|
+
case 'junit':
|
|
326
|
+
return (0, spectral_formatters_1.junit)(diagnostics, options);
|
|
327
|
+
case 'html':
|
|
328
|
+
return (0, spectral_formatters_1.html)(diagnostics, options);
|
|
329
|
+
case 'text':
|
|
330
|
+
return (0, spectral_formatters_1.text)(diagnostics, options);
|
|
331
|
+
case 'teamcity':
|
|
332
|
+
return (0, spectral_formatters_1.teamcity)(diagnostics, options);
|
|
333
|
+
case 'pretty':
|
|
334
|
+
return (0, spectral_formatters_1.pretty)(diagnostics, options);
|
|
335
|
+
default:
|
|
336
|
+
return (0, spectral_formatters_1.stylish)(diagnostics, options);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Format diagnostics in stylish format with severity grouping
|
|
341
|
+
*/
|
|
342
|
+
formatStylish(diagnostics, options) {
|
|
343
|
+
const groupedDiagnostics = diagnostics.reduce((acc, diagnostic) => {
|
|
344
|
+
const severity = diagnostic.severity;
|
|
345
|
+
if (!acc[severity]) {
|
|
346
|
+
acc[severity] = [];
|
|
347
|
+
}
|
|
348
|
+
acc[severity].push(diagnostic);
|
|
349
|
+
return acc;
|
|
350
|
+
}, {});
|
|
351
|
+
return Object.entries(groupedDiagnostics)
|
|
352
|
+
.map(([severity, diagnostics]) => {
|
|
353
|
+
return `${this.getSeverityTitle(Number(severity))} ${(0, spectral_formatters_1.stylish)(diagnostics, options)}`;
|
|
354
|
+
})
|
|
355
|
+
.join('\n');
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Get colored severity title
|
|
359
|
+
*/
|
|
360
|
+
getSeverityTitle(severity) {
|
|
361
|
+
switch (severity) {
|
|
362
|
+
case cjs_1.DiagnosticSeverity.Error:
|
|
363
|
+
return (0, chalk_1.red)('Errors');
|
|
364
|
+
case cjs_1.DiagnosticSeverity.Warning:
|
|
365
|
+
return (0, chalk_1.yellow)('Warnings');
|
|
366
|
+
case cjs_1.DiagnosticSeverity.Information:
|
|
367
|
+
return (0, chalk_1.cyan)('Information');
|
|
368
|
+
case cjs_1.DiagnosticSeverity.Hint:
|
|
369
|
+
return (0, chalk_1.green)('Hints');
|
|
370
|
+
default:
|
|
371
|
+
return 'Unknown';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.ValidationService = ValidationService;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const NO_CONTEXTS_SAVED = "These are your options to specify in the CLI what AsyncAPI file should be used:\n\t- You can provide a path to the AsyncAPI file: asyncapi <command> path/to/file/asyncapi.yml\n\t- You can provide URL to the AsyncAPI file: asyncapi <command> https://example.com/path/to/file/asyncapi.yml\n\t- You can also pass a saved context that points to your AsyncAPI file: asyncapi <command> context-name\n\t- In case you did not specify a context that you want to use, the CLI checks if there is a default context and uses it. To set default context run: asyncapi config context use mycontext\n\t- In case you did not provide any reference to AsyncAPI file and there is no default context, the CLI detects if in your current working directory you have files like asyncapi.json, asyncapi.yaml, asyncapi.yml. Just rename your file accordingly.\n";
|
|
2
|
+
declare class ContextError extends Error {
|
|
3
|
+
constructor();
|
|
4
|
+
}
|
|
5
|
+
export declare class MissingContextFileError extends ContextError {
|
|
6
|
+
constructor();
|
|
7
|
+
}
|
|
8
|
+
export declare class MissingCurrentContextError extends ContextError {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare class ContextNotFoundError extends ContextError {
|
|
12
|
+
constructor(contextName: string);
|
|
13
|
+
}
|
|
14
|
+
export declare class ContextAlreadyExistsError extends ContextError {
|
|
15
|
+
constructor(contextName: string, contextFileName: string);
|
|
16
|
+
}
|
|
17
|
+
export declare class ContextFileWrongFormatError extends ContextError {
|
|
18
|
+
constructor(contextFileName: string);
|
|
19
|
+
}
|
|
20
|
+
export declare class ContextFileEmptyError extends ContextError {
|
|
21
|
+
constructor(contextFileName: string);
|
|
22
|
+
}
|
|
23
|
+
export declare class ContextFileWriteError extends ContextError {
|
|
24
|
+
constructor(contextFileName: string);
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContextFileWriteError = exports.ContextFileEmptyError = exports.ContextFileWrongFormatError = exports.ContextAlreadyExistsError = exports.ContextNotFoundError = exports.MissingCurrentContextError = exports.MissingContextFileError = exports.NO_CONTEXTS_SAVED = void 0;
|
|
4
|
+
exports.NO_CONTEXTS_SAVED = `These are your options to specify in the CLI what AsyncAPI file should be used:
|
|
5
|
+
- You can provide a path to the AsyncAPI file: asyncapi <command> path/to/file/asyncapi.yml
|
|
6
|
+
- You can provide URL to the AsyncAPI file: asyncapi <command> https://example.com/path/to/file/asyncapi.yml
|
|
7
|
+
- You can also pass a saved context that points to your AsyncAPI file: asyncapi <command> context-name
|
|
8
|
+
- In case you did not specify a context that you want to use, the CLI checks if there is a default context and uses it. To set default context run: asyncapi config context use mycontext
|
|
9
|
+
- In case you did not provide any reference to AsyncAPI file and there is no default context, the CLI detects if in your current working directory you have files like asyncapi.json, asyncapi.yaml, asyncapi.yml. Just rename your file accordingly.
|
|
10
|
+
`;
|
|
11
|
+
const MISSING_CURRENT_CONTEXT = 'No context is set as current, please set a current context.';
|
|
12
|
+
const CONTEXT_NOT_FOUND = (contextName) => `Context "${contextName}" does not exist.`;
|
|
13
|
+
const CONTEXT_ALREADY_EXISTS = (contextName, contextFileName) => `Context with name "${contextName}" already exists in context file "${contextFileName}".`;
|
|
14
|
+
const CONTEXT_FILE_WRONG_FORMAT = (contextFileName) => `Context file "${contextFileName}" has wrong format. Make sure your context file follows the structure described in section "Context File structure" at https://www.asyncapi.com/docs/tools/cli/context#context-file-structure`;
|
|
15
|
+
const CONTEXT_FILE_EMPTY = (contextFileName) => `Context file "${contextFileName}" is empty.`;
|
|
16
|
+
const CONTEXT_FILE_WRITE_ERROR = (contextFileName) => `Error writing context file "${contextFileName}".`;
|
|
17
|
+
class ContextError extends Error {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this.name = 'ContextError';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
class MissingContextFileError extends ContextError {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.message = exports.NO_CONTEXTS_SAVED;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.MissingContextFileError = MissingContextFileError;
|
|
30
|
+
class MissingCurrentContextError extends ContextError {
|
|
31
|
+
constructor() {
|
|
32
|
+
super();
|
|
33
|
+
this.message = MISSING_CURRENT_CONTEXT;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.MissingCurrentContextError = MissingCurrentContextError;
|
|
37
|
+
class ContextNotFoundError extends ContextError {
|
|
38
|
+
constructor(contextName) {
|
|
39
|
+
super();
|
|
40
|
+
this.message = CONTEXT_NOT_FOUND(contextName);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ContextNotFoundError = ContextNotFoundError;
|
|
44
|
+
class ContextAlreadyExistsError extends ContextError {
|
|
45
|
+
constructor(contextName, contextFileName) {
|
|
46
|
+
super();
|
|
47
|
+
this.message = CONTEXT_ALREADY_EXISTS(contextName, contextFileName);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.ContextAlreadyExistsError = ContextAlreadyExistsError;
|
|
51
|
+
class ContextFileWrongFormatError extends ContextError {
|
|
52
|
+
constructor(contextFileName) {
|
|
53
|
+
super();
|
|
54
|
+
this.message = CONTEXT_FILE_WRONG_FORMAT(contextFileName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.ContextFileWrongFormatError = ContextFileWrongFormatError;
|
|
58
|
+
class ContextFileEmptyError extends ContextError {
|
|
59
|
+
constructor(contextFileName) {
|
|
60
|
+
super();
|
|
61
|
+
this.message = CONTEXT_FILE_EMPTY(contextFileName);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.ContextFileEmptyError = ContextFileEmptyError;
|
|
65
|
+
class ContextFileWriteError extends ContextError {
|
|
66
|
+
constructor(contextFileName) {
|
|
67
|
+
super();
|
|
68
|
+
this.message = CONTEXT_FILE_WRITE_ERROR(contextFileName);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ContextFileWriteError = ContextFileWriteError;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DiffBreakingChangeError = exports.DiffOverrideJSONError = exports.DiffOverrideFileError = void 0;
|
|
4
|
+
class DiffOverrideFileError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super();
|
|
7
|
+
this.name = 'DiffOverrideFileError';
|
|
8
|
+
this.message = 'Override file not found';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.DiffOverrideFileError = DiffOverrideFileError;
|
|
12
|
+
class DiffOverrideJSONError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.name = 'DiffOverrideJSONError';
|
|
16
|
+
this.message = 'Provided override file is not a valid JSON file';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.DiffOverrideJSONError = DiffOverrideJSONError;
|
|
20
|
+
class DiffBreakingChangeError extends Error {
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
this.name = 'DiffBreakingChangeError';
|
|
24
|
+
this.message = 'Breaking changes detected';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.DiffBreakingChangeError = DiffBreakingChangeError;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GeneratorError = void 0;
|
|
4
|
+
class GeneratorError extends Error {
|
|
5
|
+
constructor(err) {
|
|
6
|
+
super();
|
|
7
|
+
this.name = 'Generator Error';
|
|
8
|
+
this.message = err.message;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.GeneratorError = GeneratorError;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare class SpecificationFileError extends Error {
|
|
2
|
+
constructor();
|
|
3
|
+
}
|
|
4
|
+
export declare class SpecificationFileNotFound extends SpecificationFileError {
|
|
5
|
+
constructor(filePath?: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class SpecificationWrongFileFormat extends SpecificationFileError {
|
|
8
|
+
constructor(filePath?: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class SpecificationURLNotFound extends SpecificationFileError {
|
|
11
|
+
constructor(URL: string);
|
|
12
|
+
}
|
|
13
|
+
type From = 'file' | 'url' | 'context' | 'invalid file';
|
|
14
|
+
export declare class ErrorLoadingSpec extends Error {
|
|
15
|
+
private readonly errorMessages;
|
|
16
|
+
constructor(from?: From, param?: string);
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ErrorLoadingSpec = exports.SpecificationURLNotFound = exports.SpecificationWrongFileFormat = exports.SpecificationFileNotFound = void 0;
|
|
4
|
+
const context_error_1 = require("./context-error");
|
|
5
|
+
class SpecificationFileError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super();
|
|
8
|
+
this.name = 'SpecificationFileError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class SpecificationFileNotFound extends SpecificationFileError {
|
|
12
|
+
constructor(filePath) {
|
|
13
|
+
super();
|
|
14
|
+
if (filePath) {
|
|
15
|
+
this.message = `File ${filePath} does not exist.`;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this.message = 'We could not find any AsyncAPI file.';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
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;
|
|
30
|
+
class SpecificationURLNotFound extends SpecificationFileError {
|
|
31
|
+
constructor(URL) {
|
|
32
|
+
super();
|
|
33
|
+
this.message = `Unable to fetch specification file from url: ${URL}`;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.SpecificationURLNotFound = SpecificationURLNotFound;
|
|
37
|
+
class ErrorLoadingSpec extends Error {
|
|
38
|
+
constructor(from, param) {
|
|
39
|
+
super();
|
|
40
|
+
this.errorMessages = {
|
|
41
|
+
default: context_error_1.NO_CONTEXTS_SAVED,
|
|
42
|
+
};
|
|
43
|
+
if (from === 'file') {
|
|
44
|
+
this.name = 'error loading AsyncAPI document from file';
|
|
45
|
+
this.message = `${param} file does not exist.`;
|
|
46
|
+
}
|
|
47
|
+
if (from === 'url') {
|
|
48
|
+
this.name = 'error loading AsyncAPI document from url';
|
|
49
|
+
this.message = `Failed to download ${param}.`;
|
|
50
|
+
}
|
|
51
|
+
if (from === 'context') {
|
|
52
|
+
this.name = 'error loading AsyncAPI document from context';
|
|
53
|
+
this.message = `${param} context name does not exist.`;
|
|
54
|
+
}
|
|
55
|
+
if (from === 'invalid file') {
|
|
56
|
+
this.name = 'Invalid AsyncAPI file type';
|
|
57
|
+
this.message = 'cli only supports yml ,yaml ,json extension';
|
|
58
|
+
}
|
|
59
|
+
if (!from) {
|
|
60
|
+
this.name = 'error locating AsyncAPI document';
|
|
61
|
+
this.message = this.errorMessages.default;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.ErrorLoadingSpec = ErrorLoadingSpec;
|