@asyncapi/cli 3.1.1 → 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/README.md +4 -0
- package/assets/create-glee-app/templates/default/package-lock.json +1185 -676
- package/assets/create-glee-app/templates/tutorial/package-lock.json +1148 -554
- package/assets/create-template/templates/default/package-lock.json +55 -132
- 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 +6 -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 +3 -1
- package/lib/{core → apps/cli/internal}/flags/validate.flags.js +11 -3
- 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 +124 -1
- package/package.json +37 -22
- package/lib/commands/convert.js +0 -132
- package/lib/commands/validate.js +0 -45
- 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 -33
- package/lib/core/parser.js +0 -176
- /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
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validationMiddleware = validationMiddleware;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const problem_exception_1 = require("../exceptions/problem.exception");
|
|
6
|
+
const ajv_1 = require("../../../utils/ajv");
|
|
7
|
+
const app_openapi_1 = require("../../../utils/app-openapi");
|
|
8
|
+
const validation_service_1 = require("../../../domains/services/validation.service");
|
|
9
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
10
|
+
const ajvInstance = (0, ajv_1.createAjvInstance)();
|
|
11
|
+
/**
|
|
12
|
+
* Create AJV's validator function for given path in the OpenAPI document.
|
|
13
|
+
*/
|
|
14
|
+
function compileAjv(options) {
|
|
15
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const appOpenAPI = yield (0, app_openapi_1.getAppOpenAPI)();
|
|
17
|
+
const paths = appOpenAPI.paths || {};
|
|
18
|
+
const pathName = options.path;
|
|
19
|
+
const path = paths[String(pathName)];
|
|
20
|
+
if (!path) {
|
|
21
|
+
throw new Error(`Path "${pathName}" doesn't exist in the OpenAPI document.`);
|
|
22
|
+
}
|
|
23
|
+
const methodName = options.method;
|
|
24
|
+
const method = path[String(methodName)];
|
|
25
|
+
if (!method) {
|
|
26
|
+
throw new Error(`Method "${methodName}" for "${pathName}" path doesn't exist in the OpenAPI document.`);
|
|
27
|
+
}
|
|
28
|
+
const requestBody = method.requestBody;
|
|
29
|
+
if (!requestBody) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let schema = requestBody.content['application/json'].schema;
|
|
33
|
+
if (!schema) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
schema = Object.assign({}, schema);
|
|
37
|
+
schema['$schema'] = 'http://json-schema.org/draft-07/schema';
|
|
38
|
+
if (options.documents && schema.properties) {
|
|
39
|
+
schema.properties = Object.assign({}, schema.properties);
|
|
40
|
+
for (const field of options.documents) {
|
|
41
|
+
if (schema.properties[String(field)].items) {
|
|
42
|
+
schema.properties[String(field)] = Object.assign({}, schema.properties[String(field)]);
|
|
43
|
+
schema.properties[String(field)].items = true;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
schema.properties[String(field)] = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return ajvInstance.compile(schema);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function validateRequestBody(validate, body) {
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const valid = validate(body);
|
|
56
|
+
const errors = validate.errors && [...validate.errors];
|
|
57
|
+
if (valid === false) {
|
|
58
|
+
throw new problem_exception_1.ProblemException({
|
|
59
|
+
type: 'invalid-request-body',
|
|
60
|
+
title: 'Invalid Request Body',
|
|
61
|
+
status: 422,
|
|
62
|
+
validationErrors: errors,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function validateSingleDocument(asyncapi, path, validationService) {
|
|
68
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
if (typeof asyncapi === 'object') {
|
|
70
|
+
asyncapi = JSON.stringify(asyncapi);
|
|
71
|
+
}
|
|
72
|
+
const specFile = new SpecificationFile_1.Specification(asyncapi, { fileURL: path });
|
|
73
|
+
return validationService
|
|
74
|
+
.validateDocument(specFile, {
|
|
75
|
+
'fail-severity': 'error',
|
|
76
|
+
suppressAllWarnings: false,
|
|
77
|
+
})
|
|
78
|
+
.then((result) => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
if (!result.success || ((_a = result.data) === null || _a === void 0 ? void 0 : _a.status) !== 'valid') {
|
|
81
|
+
throw new problem_exception_1.ProblemException({
|
|
82
|
+
type: 'invalid-asyncapi-document',
|
|
83
|
+
title: 'Invalid AsyncAPI Document',
|
|
84
|
+
status: 422,
|
|
85
|
+
detail: result.error || 'The provided AsyncAPI document is invalid.',
|
|
86
|
+
diagnostics: result.diagnostics || ((_b = result.data) === null || _b === void 0 ? void 0 : _b.diagnostics),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return result.data;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function validateListDocuments(asyncapis, path, validationService) {
|
|
94
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const validationResults = [];
|
|
96
|
+
for (const asyncapi of asyncapis) {
|
|
97
|
+
const parsed = yield validateSingleDocument(asyncapi, path, validationService);
|
|
98
|
+
if (parsed) {
|
|
99
|
+
validationResults.push(parsed);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new problem_exception_1.ProblemException({
|
|
103
|
+
type: 'invalid-asyncapi-document',
|
|
104
|
+
title: 'Invalid AsyncAPI Document',
|
|
105
|
+
status: 422,
|
|
106
|
+
detail: 'One or more provided AsyncAPI documents are invalid.',
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return validationResults;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Validate RequestBody and sent AsyncAPI document(s) for given path and method based on the OpenAPI Document.
|
|
115
|
+
*/
|
|
116
|
+
function validationMiddleware(options) {
|
|
117
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
options.version = options.version || 'v1';
|
|
119
|
+
const validate = yield compileAjv(options);
|
|
120
|
+
const documents = options.documents || [];
|
|
121
|
+
return (req, res, next) => tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
var _a;
|
|
123
|
+
// Check if the condition is met
|
|
124
|
+
if (options.condition && !options.condition(req)) {
|
|
125
|
+
return next();
|
|
126
|
+
}
|
|
127
|
+
try {
|
|
128
|
+
if (!validate) {
|
|
129
|
+
throw new problem_exception_1.ProblemException({
|
|
130
|
+
type: 'invalid-request-body',
|
|
131
|
+
title: 'Invalid Request Body',
|
|
132
|
+
status: 422,
|
|
133
|
+
detail: `Request body validation is not supported for "${options.path}" path with "${options.method}" method.`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
yield validateRequestBody(validate, req.body);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof problem_exception_1.ProblemException) {
|
|
140
|
+
return next(error);
|
|
141
|
+
}
|
|
142
|
+
// Handle unexpected errors
|
|
143
|
+
return next(new problem_exception_1.ProblemException({
|
|
144
|
+
type: 'internal-server-error',
|
|
145
|
+
title: 'Internal Server Error',
|
|
146
|
+
status: 500,
|
|
147
|
+
detail: `An unexpected error occurred during request validation: ${(_a = error.message) !== null && _a !== void 0 ? _a : 'Unknown error'}`,
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
const parserConfig = {
|
|
151
|
+
__unstable: {
|
|
152
|
+
resolver: {
|
|
153
|
+
resolvers: [
|
|
154
|
+
// @TODO: Add Cookie Based Resolvers after migration and understanding some
|
|
155
|
+
// details about how to use them in the new parser-js version.
|
|
156
|
+
],
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
const validationService = new validation_service_1.ValidationService(parserConfig);
|
|
161
|
+
const resolveURL = req.header('x-asyncapi-resolve-url') ||
|
|
162
|
+
req.header('referer') ||
|
|
163
|
+
req.header('origin') ||
|
|
164
|
+
'';
|
|
165
|
+
try {
|
|
166
|
+
req.asyncapi = req.asyncapi || {};
|
|
167
|
+
for (const field of documents) {
|
|
168
|
+
const body = req.body[String(field)];
|
|
169
|
+
if (Array.isArray(body)) {
|
|
170
|
+
const results = yield validateListDocuments(body, resolveURL, validationService);
|
|
171
|
+
const parsedDocuments = results.map((result) => result.document);
|
|
172
|
+
req.asyncapi.parsedDocuments = parsedDocuments;
|
|
173
|
+
req.asyncapi.validationResults = results;
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
const result = yield validateSingleDocument(body, resolveURL, validationService);
|
|
177
|
+
req.asyncapi.parsedDocument = result === null || result === void 0 ? void 0 : result.document;
|
|
178
|
+
req.asyncapi.validationResult = result;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
next();
|
|
182
|
+
}
|
|
183
|
+
catch (err) {
|
|
184
|
+
return next(err);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
const TYPES_400 = [
|
|
190
|
+
'null-or-falsey-document',
|
|
191
|
+
'impossible-to-convert-to-json',
|
|
192
|
+
'invalid-document-type',
|
|
193
|
+
'invalid-json',
|
|
194
|
+
'invalid-yaml',
|
|
195
|
+
];
|
|
196
|
+
/**
|
|
197
|
+
* Some error types have to be treated as 400 HTTP Status Code, another as 422.
|
|
198
|
+
*/
|
|
199
|
+
function retrieveStatusCode(type) {
|
|
200
|
+
if (TYPES_400.includes(type)) {
|
|
201
|
+
return 400;
|
|
202
|
+
}
|
|
203
|
+
return 422;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Merges fields from ParserError to ProblemException.
|
|
207
|
+
*/
|
|
208
|
+
function mergeParserError(error, parserError) {
|
|
209
|
+
if (parserError.detail) {
|
|
210
|
+
error.set('detail', parserError.detail);
|
|
211
|
+
}
|
|
212
|
+
if (parserError.validationErrors) {
|
|
213
|
+
error.set('validationErrors', parserError.validationErrors);
|
|
214
|
+
}
|
|
215
|
+
if (parserError.parsedJSON) {
|
|
216
|
+
error.set('parsedJSON', parserError.parsedJSON);
|
|
217
|
+
}
|
|
218
|
+
if (parserError.location) {
|
|
219
|
+
error.set('location', parserError.location);
|
|
220
|
+
}
|
|
221
|
+
if (parserError.refs) {
|
|
222
|
+
error.set('refs', parserError.refs);
|
|
223
|
+
}
|
|
224
|
+
return error;
|
|
225
|
+
}
|
|
226
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
227
|
+
function tryConvertToProblemException(err) {
|
|
228
|
+
const typeName = err.type.replace('https://github.com/asyncapi/parser-js/', '');
|
|
229
|
+
const error = new problem_exception_1.ProblemException({
|
|
230
|
+
type: typeName,
|
|
231
|
+
title: err.title,
|
|
232
|
+
status: retrieveStatusCode(typeName),
|
|
233
|
+
});
|
|
234
|
+
mergeParserError(error, err);
|
|
235
|
+
return error;
|
|
236
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
// include configs in the `dist` folder
|
|
5
|
+
require("./configs/production.json");
|
|
6
|
+
require("./configs/development.json");
|
|
7
|
+
require("./configs/test.json");
|
|
8
|
+
// for `config` module
|
|
9
|
+
process.env['NODE_CONFIG_DIR'] = `${__dirname}/configs`;
|
|
10
|
+
const app_1 = require("./app");
|
|
11
|
+
const _1 = require(".");
|
|
12
|
+
function main() {
|
|
13
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
const app = new app_1.App(_1.CONTROLLERS);
|
|
15
|
+
yield app.init();
|
|
16
|
+
app.listen();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
main();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../internal/base"));
|
|
5
5
|
const bundler_1 = tslib_1.__importDefault(require("@asyncapi/bundler"));
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
-
const SpecificationFile_1 = require("
|
|
9
|
-
const bundle_flags_1 = require("../
|
|
8
|
+
const SpecificationFile_1 = require("../../../domains/models/SpecificationFile");
|
|
9
|
+
const bundle_flags_1 = require("../internal/flags/bundle.flags");
|
|
10
10
|
const { writeFile } = fs_1.promises;
|
|
11
11
|
class Bundle extends base_1.default {
|
|
12
12
|
run() {
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
6
6
|
const fs_1 = require("fs");
|
|
7
7
|
const os_1 = require("os");
|
|
8
|
-
const analytics_flags_1 = require("../../
|
|
8
|
+
const analytics_flags_1 = require("../../internal/flags/config/analytics.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
const { readFile, writeFile } = fs_1.promises;
|
|
11
11
|
class Analytics extends base_1.default {
|
|
12
12
|
run() {
|
|
13
13
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const { flags } = yield this.parse(Analytics);
|
|
15
|
-
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
15
|
+
const analyticsConfigFile = process.env.ASYNCAPI_METRICS_CONFIG_PATH ||
|
|
16
|
+
(0, path_1.join)((0, os_1.homedir)(), '.asyncapi-analytics');
|
|
16
17
|
try {
|
|
17
18
|
const analyticsConfigFileContent = JSON.parse(yield readFile((0, path_1.resolve)(analyticsConfigFile), { encoding: 'utf8' }));
|
|
18
19
|
if (flags.disable) {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
6
|
-
const Context_1 = require("
|
|
7
|
-
const context_error_1 = require("
|
|
8
|
-
const context_flags_1 = require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
7
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
8
|
+
const context_flags_1 = require("../../../internal/flags/config/context.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
class ContextAdd extends base_1.default {
|
|
11
11
|
run() {
|
|
@@ -34,7 +34,13 @@ class ContextAdd extends base_1.default {
|
|
|
34
34
|
ContextAdd.description = 'Add a context to the store';
|
|
35
35
|
ContextAdd.flags = (0, context_flags_1.addFlags)();
|
|
36
36
|
ContextAdd.args = {
|
|
37
|
-
'context-name': core_1.Args.string({
|
|
38
|
-
|
|
37
|
+
'context-name': core_1.Args.string({
|
|
38
|
+
description: 'context name',
|
|
39
|
+
required: true,
|
|
40
|
+
}),
|
|
41
|
+
'spec-file-path': core_1.Args.string({
|
|
42
|
+
description: 'file path of the spec file',
|
|
43
|
+
required: true,
|
|
44
|
+
}),
|
|
39
45
|
};
|
|
40
46
|
exports.default = ContextAdd;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
5
|
-
const Context_1 = require("
|
|
6
|
-
const context_error_1 = require("
|
|
7
|
-
const global_flags_1 = require("../../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
5
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
6
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
7
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
8
8
|
const picocolors_1 = require("picocolors");
|
|
9
9
|
class ContextCurrent extends base_1.default {
|
|
10
10
|
run() {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
6
|
-
const Context_1 = require("
|
|
7
|
-
const context_error_1 = require("
|
|
8
|
-
const global_flags_1 = require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
7
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
8
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
class ContextEdit extends base_1.default {
|
|
11
11
|
run() {
|
|
@@ -32,7 +32,13 @@ class ContextEdit extends base_1.default {
|
|
|
32
32
|
ContextEdit.description = 'Edit a context in the store';
|
|
33
33
|
ContextEdit.flags = (0, global_flags_1.helpFlag)();
|
|
34
34
|
ContextEdit.args = {
|
|
35
|
-
'context-name': core_1.Args.string({
|
|
36
|
-
|
|
35
|
+
'context-name': core_1.Args.string({
|
|
36
|
+
description: 'context name',
|
|
37
|
+
required: true,
|
|
38
|
+
}),
|
|
39
|
+
'new-spec-file-path': core_1.Args.string({
|
|
40
|
+
description: 'file path of the spec file',
|
|
41
|
+
required: true,
|
|
42
|
+
}),
|
|
37
43
|
};
|
|
38
44
|
exports.default = ContextEdit;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
6
|
class Context extends base_1.default {
|
|
7
7
|
run() {
|
|
8
8
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
6
|
-
const Context_1 = require("
|
|
7
|
-
const global_flags_1 = require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
7
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
8
8
|
const picocolors_1 = require("picocolors");
|
|
9
9
|
class ContextInit extends base_1.default {
|
|
10
10
|
run() {
|
|
@@ -23,6 +23,9 @@ ContextInit.contextFilePathMessage = `Specify directory in which context file sh
|
|
|
23
23
|
- root of current repository : ${(0, picocolors_1.blueBright)('asyncapi config context init ./ ')}
|
|
24
24
|
- user's home directory : ${(0, picocolors_1.blueBright)('asyncapi config context init ~`')}`;
|
|
25
25
|
ContextInit.args = {
|
|
26
|
-
'context-file-path': core_1.Args.string({
|
|
26
|
+
'context-file-path': core_1.Args.string({
|
|
27
|
+
description: `${ContextInit.contextFilePathMessage}`,
|
|
28
|
+
required: false,
|
|
29
|
+
}),
|
|
27
30
|
};
|
|
28
31
|
exports.default = ContextInit;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
5
|
-
const Context_1 = require("
|
|
6
|
-
const context_error_1 = require("
|
|
7
|
-
const global_flags_1 = require("../../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
5
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
6
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
7
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
8
8
|
const picocolors_1 = require("picocolors");
|
|
9
9
|
class ContextList extends base_1.default {
|
|
10
10
|
run() {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
6
|
-
const Context_1 = require("
|
|
7
|
-
const context_error_1 = require("
|
|
8
|
-
const global_flags_1 = require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
7
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
8
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
class ContextRemove extends base_1.default {
|
|
11
11
|
run() {
|
|
@@ -31,6 +31,9 @@ class ContextRemove extends base_1.default {
|
|
|
31
31
|
ContextRemove.description = 'Delete a context from the store';
|
|
32
32
|
ContextRemove.flags = (0, global_flags_1.helpFlag)();
|
|
33
33
|
ContextRemove.args = {
|
|
34
|
-
'context-name': core_1.Args.string({
|
|
34
|
+
'context-name': core_1.Args.string({
|
|
35
|
+
description: 'Name of the context to delete',
|
|
36
|
+
required: true,
|
|
37
|
+
}),
|
|
35
38
|
};
|
|
36
39
|
exports.default = ContextRemove;
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
const base_1 = tslib_1.__importDefault(require("../../../
|
|
6
|
-
const Context_1 = require("
|
|
7
|
-
const context_error_1 = require("
|
|
8
|
-
const global_flags_1 = require("../../../
|
|
5
|
+
const base_1 = tslib_1.__importDefault(require("../../../internal/base"));
|
|
6
|
+
const Context_1 = require("../../../../../domains/models/Context");
|
|
7
|
+
const context_error_1 = require("../../../../../errors/context-error");
|
|
8
|
+
const global_flags_1 = require("../../../internal/flags/global.flags");
|
|
9
9
|
const picocolors_1 = require("picocolors");
|
|
10
10
|
class ContextUse extends base_1.default {
|
|
11
11
|
run() {
|
|
@@ -32,6 +32,9 @@ class ContextUse extends base_1.default {
|
|
|
32
32
|
ContextUse.description = 'Set a context as current';
|
|
33
33
|
ContextUse.flags = (0, global_flags_1.helpFlag)();
|
|
34
34
|
ContextUse.args = {
|
|
35
|
-
'context-name': core_1.Args.string({
|
|
35
|
+
'context-name': core_1.Args.string({
|
|
36
|
+
description: 'name of the saved context',
|
|
37
|
+
required: true,
|
|
38
|
+
}),
|
|
36
39
|
};
|
|
37
40
|
exports.default = ContextUse;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
5
|
const core_1 = require("@oclif/core");
|
|
6
6
|
class Config extends base_1.default {
|
|
7
7
|
run() {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const base_1 = tslib_1.__importDefault(require("../../
|
|
5
|
-
const global_flags_1 = require("../../
|
|
4
|
+
const base_1 = tslib_1.__importDefault(require("../../internal/base"));
|
|
5
|
+
const global_flags_1 = require("../../internal/flags/global.flags");
|
|
6
6
|
const picocolors_1 = require("picocolors");
|
|
7
7
|
class Versions extends base_1.default {
|
|
8
8
|
run() {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import Command from '../
|
|
1
|
+
import Command from '../internal/base';
|
|
2
2
|
export default class Convert extends Command {
|
|
3
3
|
static specFile: any;
|
|
4
4
|
static metricsMetadata: any;
|
|
5
5
|
static description: string;
|
|
6
|
+
private conversionService;
|
|
6
7
|
static flags: {
|
|
7
8
|
proxyHost: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
8
9
|
proxyPort: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces").CustomOptions>;
|
|
@@ -16,11 +17,5 @@ export default class Convert extends Command {
|
|
|
16
17
|
'spec-file': import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
|
|
17
18
|
};
|
|
18
19
|
run(): Promise<void>;
|
|
19
|
-
private handleConversion;
|
|
20
|
-
private convertOpenAPI;
|
|
21
|
-
private convertAsyncAPI;
|
|
22
|
-
private convertPostman;
|
|
23
|
-
private formatConvertedFile;
|
|
24
|
-
private handleOutput;
|
|
25
20
|
private handleError;
|
|
26
21
|
}
|