@asyncapi/generator 1.10.14 → 1.12.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/CODEOWNERS
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
# The default owners are automatically added as reviewers when you open a pull request unless different owners are specified in the file.
|
|
8
8
|
|
|
9
|
-
* @
|
|
9
|
+
* @derberg @magicmatatjahu @jonaslagoni @asyncapi-bot-eve
|
|
10
10
|
|
|
11
11
|
# All .md files
|
|
12
|
-
*.md @Florence-Njeri @
|
|
12
|
+
*.md @Florence-Njeri @derberg @asyncapi-bot-eve
|
|
@@ -8,7 +8,7 @@ The `generator` property from `package.json` file must contain a JSON object tha
|
|
|
8
8
|
|Name|Type|Description|
|
|
9
9
|
|---|---|---|
|
|
10
10
|
|`renderer`| String | Its value can be either `react` or `nunjucks` (default).
|
|
11
|
-
|`apiVersion`| String | Determines which **major** version of the [Parser-API](https://github.com/asyncapi/parser-api) the template uses. For example, `
|
|
11
|
+
|`apiVersion`| String | Determines which **major** version of the [Parser-API](https://github.com/asyncapi/parser-api) the template uses. For example, `v2` for `v2.x.x`. If not specified, the Generator assumes the template is not compatible with the Parser-API so it will use the [Parser-JS v1 API](https://github.com/asyncapi/parser-js/tree/v1.18.1#api-documentation). For templates that need to support AsyncAPI specification v3 make sure to use `v2` [Parser-API](https://github.com/asyncapi/parser-api). If the template uses a version of the Parser-API that is not supported by the Generator, the Generator will throw an error.
|
|
12
12
|
|`supportedProtocols`| [String] | A list with all the protocols this template supports.
|
|
13
13
|
|`parameters`| Object[String, Object] | An object with all the parameters that can be passed when generating the template. When using the command line, it's done by indicating `--param name=value` or `-p name=value`.
|
|
14
14
|
|`parameters[param].description`| String | A user-friendly description about the parameter.
|
|
@@ -28,7 +28,7 @@ The `generator` property from `package.json` file must contain a JSON object tha
|
|
|
28
28
|
"generator":
|
|
29
29
|
{
|
|
30
30
|
"renderer": "react",
|
|
31
|
-
"apiVersion": "
|
|
31
|
+
"apiVersion": "v2",
|
|
32
32
|
"supportedProtocols": ["amqp", "mqtt"],
|
|
33
33
|
"parameters": {
|
|
34
34
|
"server": {
|
package/lib/generator.js
CHANGED
|
@@ -179,7 +179,7 @@ class Generator {
|
|
|
179
179
|
validateTemplateConfig(this.templateConfig, this.templateParams, asyncapiDocument);
|
|
180
180
|
await this.configureTemplate();
|
|
181
181
|
|
|
182
|
-
// use
|
|
182
|
+
// use the expected document API based on `templateConfig.apiVersion` value
|
|
183
183
|
this.asyncapi = asyncapiDocument = getProperApiDocument(asyncapiDocument, this.templateConfig);
|
|
184
184
|
|
|
185
185
|
if (!isReactTemplate(this.templateConfig)) {
|
|
@@ -261,7 +261,7 @@ class Generator {
|
|
|
261
261
|
/** @type {AsyncAPIDocument} Parsed AsyncAPI schema. See {@link https://github.com/asyncapi/parser-js/blob/master/API.md#module_@asyncapi/parser+AsyncAPIDocument|AsyncAPIDocument} for details on object structure. */
|
|
262
262
|
const { document, diagnostics } = await parse(asyncapiString, parseOptions, this);
|
|
263
263
|
if (!document) {
|
|
264
|
-
const err = new Error('Input is not a
|
|
264
|
+
const err = new Error('Input is not a correct AsyncAPI document so it cannot be processed.');
|
|
265
265
|
err.diagnostics = diagnostics;
|
|
266
266
|
throw err;
|
|
267
267
|
}
|
|
@@ -436,7 +436,7 @@ class Generator {
|
|
|
436
436
|
}
|
|
437
437
|
});
|
|
438
438
|
}
|
|
439
|
-
|
|
439
|
+
|
|
440
440
|
if (asyncapiDocument.hasComponents()) {
|
|
441
441
|
for (const [key, value] of Object.entries(asyncapiDocument.components().parameters())) {
|
|
442
442
|
parameters.set(key, value);
|
package/lib/parser.js
CHANGED
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
const { OpenAPISchemaParser } = require('@asyncapi/openapi-schema-parser');
|
|
5
|
-
const { AvroSchemaParser } = require('@asyncapi/avro-schema-parser');
|
|
6
|
-
const { RamlDTSchemaParser } = require('@asyncapi/raml-dt-schema-parser');
|
|
2
|
+
const { convertToOldAPI } = require('@asyncapi/parser');
|
|
3
|
+
const { ConvertDocumentParserAPIVersion, NewParser } = require('@smoya/multi-parser');
|
|
7
4
|
|
|
8
5
|
const parser = module.exports;
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
7
|
+
/**
|
|
8
|
+
* Conver the template defined value `apiVersion: 'v1'` to only contain the numeric value `1`.
|
|
9
|
+
*/
|
|
10
|
+
parser.sanitizeTemplateApiVersion = (apiVersion) => {
|
|
11
|
+
if (apiVersion && apiVersion.length > 1) {
|
|
12
|
+
return apiVersion.substring('1');
|
|
13
|
+
}
|
|
14
|
+
return apiVersion;
|
|
15
|
+
};
|
|
17
16
|
|
|
18
17
|
parser.parse = (asyncapi, oldOptions, generator) => {
|
|
18
|
+
let apiVersion = this.sanitizeTemplateApiVersion(generator.templateConfig.apiVersion);
|
|
19
|
+
// Defaulting to apiVersion v1 to convert it to the Parser-API v1 afterwards.
|
|
20
|
+
if (!this.usesNewAPI(generator.templateConfig)) {
|
|
21
|
+
apiVersion = '1';
|
|
22
|
+
}
|
|
19
23
|
const options = convertOldOptionsToNew(oldOptions, generator);
|
|
20
|
-
|
|
24
|
+
const parser = NewParser(apiVersion, {parserOptions: options, includeSchemaParsers: true});
|
|
25
|
+
return parser.parse(asyncapi, options);
|
|
21
26
|
};
|
|
22
27
|
|
|
28
|
+
/**
|
|
29
|
+
* If the template expect one of the Parser-API versions, it must be above 0
|
|
30
|
+
*/
|
|
23
31
|
parser.usesNewAPI = (templateConfig = {}) => {
|
|
24
|
-
return templateConfig.apiVersion
|
|
32
|
+
return Number(this.sanitizeTemplateApiVersion(templateConfig.apiVersion)) > 0;
|
|
25
33
|
};
|
|
26
34
|
|
|
27
|
-
|
|
28
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Based on the current parsed AsyncAPI document, convert it to expected API version from the template.
|
|
37
|
+
*/
|
|
38
|
+
parser.getProperApiDocument = (asyncapiDocument, templateConfig = {}) => {
|
|
39
|
+
const apiVersion = this.sanitizeTemplateApiVersion(templateConfig.apiVersion);
|
|
40
|
+
if (apiVersion === undefined) {
|
|
41
|
+
// Convert to old API from JS Parser v1
|
|
42
|
+
return convertToOldAPI(asyncapiDocument);
|
|
43
|
+
}
|
|
44
|
+
return ConvertDocumentParserAPIVersion(asyncapiDocument, apiVersion);
|
|
29
45
|
};
|
|
30
46
|
|
|
31
47
|
// The new options for the v2 Parser are different from those for the v1 version, but in order not to release Generator v2, we are converting the old options of Parser to the new ones.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asyncapi/generator",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "The AsyncAPI generator. It can generate documentation, code, anything!",
|
|
5
5
|
"main": "./lib/generator.js",
|
|
6
6
|
"bin": {
|
|
@@ -48,12 +48,10 @@
|
|
|
48
48
|
"license": "Apache-2.0",
|
|
49
49
|
"homepage": "https://github.com/asyncapi/generator",
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@asyncapi/
|
|
52
|
-
"@asyncapi/
|
|
53
|
-
"@asyncapi/openapi-schema-parser": "^3.0.4",
|
|
54
|
-
"@asyncapi/parser": "^2.1.0",
|
|
55
|
-
"@asyncapi/raml-dt-schema-parser": "^4.0.4",
|
|
51
|
+
"@asyncapi/generator-react-sdk": "^0.2.23",
|
|
52
|
+
"@asyncapi/parser": "2.1.0",
|
|
56
53
|
"@npmcli/arborist": "^2.2.4",
|
|
54
|
+
"@smoya/multi-parser": "3.0.0",
|
|
57
55
|
"ajv": "^8.12.0",
|
|
58
56
|
"chokidar": "^3.4.0",
|
|
59
57
|
"commander": "^6.1.0",
|