diff --git a/docs/configuration-file.md b/docs/configuration-file.md index f8ceb2635..0f37a3e92 100644 --- a/docs/configuration-file.md +++ b/docs/configuration-file.md @@ -8,7 +8,7 @@ The `generator` property from `package.json` file must contain a JSON object tha |Name|Type|Description| |---|---|---| |`renderer`| String | Its value can be either `react` or `nunjucks` (default). -|`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. +|`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 `v3` [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. |`supportedProtocols`| [String] | A list with all the protocols this template supports. |`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`. |`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 "generator": { "renderer": "react", - "apiVersion": "v2", + "apiVersion": "v3", "supportedProtocols": ["amqp", "mqtt"], "parameters": { "server": { diff --git a/lib/templateConfigValidator.js b/lib/templateConfigValidator.js index b6be15864..3b57ef759 100644 --- a/lib/templateConfigValidator.js +++ b/lib/templateConfigValidator.js @@ -11,7 +11,8 @@ const ajv = new Ajv({ allErrors: true }); // See https://github.com/asyncapi/parser-api const supportedParserAPIMajorVersions = [ 'v1', - 'v2' + 'v2', + 'v3' ]; /** diff --git a/package.json b/package.json index f85f90f49..91a1a14ef 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@asyncapi/generator-react-sdk": "^1.0.1", "@asyncapi/parser": "^2.1.1", "@npmcli/arborist": "^2.2.4", - "@smoya/multi-parser": "^4.0.0", + "@smoya/multi-parser": "^5.0.0", "ajv": "^8.12.0", "chokidar": "^3.4.0", "commander": "^6.1.0", diff --git a/test/parser.test.js b/test/parser.test.js index da7d76c38..93bda806b 100644 --- a/test/parser.test.js +++ b/test/parser.test.js @@ -6,9 +6,9 @@ const dummyV3Document = fs.readFileSync(path.resolve(__dirname, './docs/dummyV3. describe('Parser', () => { describe('sanitizeTemplateApiVersion', () => { - it('should return version number when given `v2` syntax', () => { - const rawVersion = 'v2'; - const expectedVersion = 2; + it('should return version number when given `v99` syntax', () => { + const rawVersion = 'v99'; + const expectedVersion = 99; const sanitizedVersion = sanitizeTemplateApiVersion(rawVersion); expect(sanitizedVersion).toStrictEqual(expectedVersion); @@ -45,6 +45,14 @@ describe('Parser', () => { expect(isUsingNewAPI).toStrictEqual(true); }); + it('should use new parser api if v3', () => { + const templateConfig = { + apiVersion: 'v3' + }; + const isUsingNewAPI = usesNewAPI(templateConfig); + + expect(isUsingNewAPI).toStrictEqual(true); + }); it('should not use new API if no apiVersion', () => { const templateConfig = { }; const isUsingNewAPI = usesNewAPI(templateConfig); @@ -65,6 +73,12 @@ describe('Parser', () => { expect(parsedDocument).toBeDefined(); expect(parsedDocument.document.version()).toEqual('2.3.0'); }); + it('should be able to parse AsyncAPI v2 document for parser API v3', async () => { + const parsedDocument = await parse(dummyV2Document, {}, {templateConfig: {apiVersion: 'v3'}}); + + expect(parsedDocument).toBeDefined(); + expect(parsedDocument.document.version()).toEqual('2.3.0'); + }); it('should not be able to parse AsyncAPI v3 document for parser API v1', async () => { const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v1'}}); @@ -80,6 +94,12 @@ describe('Parser', () => { it('should be able to parse AsyncAPI v3 document for parser API v2', async () => { const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v2'}}); + expect(parsedDocument).toBeDefined(); + expect(parsedDocument.document.version()).toEqual('3.0.0'); + }); + it('should be able to parse AsyncAPI v3 document for parser API v3', async () => { + const parsedDocument = await parse(dummyV3Document, {}, {templateConfig: {apiVersion: 'v3'}}); + expect(parsedDocument).toBeDefined(); expect(parsedDocument.document.version()).toEqual('3.0.0'); });