From 2e36c9c962f0cf17948b8a7500da4e1be37957e9 Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Mon, 20 Nov 2023 05:57:04 -1000 Subject: [PATCH] feat: add parser API v3 support (#1066) --- docs/configuration-file.md | 4 +- lib/templateConfigValidator.js | 3 +- package-lock.json | 201 ++++++++++++++++++++++++--------- package.json | 3 +- test/parser.test.js | 26 ++++- 5 files changed, 178 insertions(+), 59 deletions(-) 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-lock.json b/package-lock.json index ce196f8b8..d01edb8e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,10 +9,12 @@ "version": "1.14.3", "license": "Apache-2.0", "dependencies": { + "@asyncapi/generator-react-sdk": "^1.0.1", + "@asyncapi/parser": "^2.1.1", "@asyncapi/generator-react-sdk": "^1.0.2", "@asyncapi/parser": "^2.1.2", "@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", @@ -23,7 +25,6 @@ "js-yaml": "^3.13.1", "levenshtein-edit-distance": "^2.0.5", "loglevel": "^1.6.8", - "markdown-it": "^12.3.2", "minimatch": "^3.0.4", "node-fetch": "^2.6.0", "nunjucks": "^3.2.0", @@ -67,11 +68,11 @@ } }, "node_modules/@asyncapi/avro-schema-parser": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/@asyncapi/avro-schema-parser/-/avro-schema-parser-3.0.3.tgz", - "integrity": "sha512-XprbDYPFJ0nc963hPCjbEmM3iu6ypKg/70EFVl0MZJCLbLw/+gBbPy95uV3Qaofm5UQgSI+aTobGhc8rMre4VA==", + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@asyncapi/avro-schema-parser/-/avro-schema-parser-3.0.4.tgz", + "integrity": "sha512-2EwTS+0deHsqIJG41dJGE2/O9pD1RJZpUCahz24tgZzcK/GQM1HBuoVvqBkPcloS9EeOXo/ZcfCMAvflj5UB/g==", "dependencies": { - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "^2.1.1", "@types/json-schema": "^7.0.11", "avsc": "^5.7.6" } @@ -140,11 +141,11 @@ } }, "node_modules/@asyncapi/openapi-schema-parser": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/@asyncapi/openapi-schema-parser/-/openapi-schema-parser-3.0.4.tgz", - "integrity": "sha512-nfZbL3dTpIQ3K+/V05FBpgOPi7dDWZkqZG8e7pKwtNhwZ0YLBFWTw6RpocztlBlcieFggxZqLm4BT5I1cQbK+Q==", + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@asyncapi/openapi-schema-parser/-/openapi-schema-parser-3.0.5.tgz", + "integrity": "sha512-2CPP0arkI/ibXTdae6DqeQyor3xuSf0GOyh0+yFPqVkbiYPBkC8K2UNbQ610vt8KpcEFeijX+7YuV+FTuQ5CHg==", "dependencies": { - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "^2.1.1", "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", "ajv": "^8.11.0", "ajv-errors": "^3.0.0", @@ -232,21 +233,21 @@ } }, "node_modules/@asyncapi/protobuf-schema-parser": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@asyncapi/protobuf-schema-parser/-/protobuf-schema-parser-3.0.0.tgz", - "integrity": "sha512-kjoLrll611K+xYC/iBUlSnZsCHbrhL999ItVHZhObUOjUB991XgonqbSAaihiiDXTYgceOLhJKAN5llkV/LOOA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@asyncapi/protobuf-schema-parser/-/protobuf-schema-parser-3.0.1.tgz", + "integrity": "sha512-w6y7/jvnCBwwhAee7/uv6Cb31YAbDm3I6V9s7Jj+MSStA91WOEq1rOFm4YHdJ23oYFbWaQmc5+8MLTnQBGfc4Q==", "dependencies": { - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "^2.1.1", "@types/protocol-buffers-schema": "^3.4.1", "protocol-buffers-schema": "^3.6.0" } }, "node_modules/@asyncapi/raml-dt-schema-parser": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/@asyncapi/raml-dt-schema-parser/-/raml-dt-schema-parser-4.0.4.tgz", - "integrity": "sha512-kKam4jwYYdwqoV5zkEb3YEb8VOrN0785fc4ByazxRd+BT/RnkQTLspjTY/akdDs9DLmU4ChP73Z0vqpek6wojA==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@asyncapi/raml-dt-schema-parser/-/raml-dt-schema-parser-4.0.5.tgz", + "integrity": "sha512-pIxaQo3p34LIi8RQzgPexv5JnydGEcDr8TVvMzyzu9Z1hPyZTX0+nOjfNAlcsNN7Nq34d18r0oKxf+Ml5rMoEQ==", "dependencies": { - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "^2.1.1", "js-yaml": "^4.1.0", "ramldt2jsonschema": "^1.2.3", "webapi-parser": "^0.5.0" @@ -2936,16 +2937,17 @@ } }, "node_modules/@smoya/multi-parser": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@smoya/multi-parser/-/multi-parser-4.0.0.tgz", - "integrity": "sha512-NgPxSaB3YqwrIVe7AtQ/wh9I2J0BHR4lP0PdqirYYrc0XXRwdDjIRrywEc2jjECWsL7tuGU/QtGMGIVaJe6ZYA==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@smoya/multi-parser/-/multi-parser-5.0.0.tgz", + "integrity": "sha512-8cBG+pD478YHblQafBDngubW6lVcxJK+WJb0EtMnPYhP9upMBceRAnWRVL1RgZ5t/3C2C9DsjOo7IazW78Kf5g==", "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.3", "@asyncapi/openapi-schema-parser": "^3.0.4", "@asyncapi/protobuf-schema-parser": "^3.0.0", "@asyncapi/raml-dt-schema-parser": "^4.0.4", - "parserv2": "npm:@asyncapi/parser@^2.1.0", - "parserv3": "npm:@asyncapi/parser@^3.0.0-next-major-spec.3" + "parserapiv1": "npm:@asyncapi/parser@^2.1.0", + "parserapiv2": "npm:@asyncapi/parser@3.0.0-next-major-spec.8", + "parserapiv3": "npm:@asyncapi/parser@^3.0.0-next-major-spec.10" } }, "node_modules/@stoplight/better-ajv-errors": { @@ -5325,6 +5327,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", "integrity": "sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==", + "dev": true, "funding": { "url": "https://github.com/fb55/entities?sponsor=1" } @@ -9791,6 +9794,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz", "integrity": "sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==", + "dev": true, "dependencies": { "uc.micro": "^1.0.1" } @@ -10028,6 +10032,7 @@ "version": "12.3.2", "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", "integrity": "sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==", + "dev": true, "dependencies": { "argparse": "^2.0.1", "entities": "~2.1.0", @@ -10052,7 +10057,8 @@ "node_modules/markdown-it/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true }, "node_modules/markdown-link": { "version": "0.1.1", @@ -10110,7 +10116,8 @@ "node_modules/mdurl": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz", - "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==" + "integrity": "sha512-/sKlQJCBYVY9Ers9hqzKou4H6V5UWc/M59TH2dvkt+84itfnq7uFOMLpOiOS4ujvHP4etln18fmIxA5R5fll0g==", + "dev": true }, "node_modules/merge-stream": { "version": "2.0.0", @@ -11141,14 +11148,97 @@ "integrity": "sha512-fxNG2sQjHvlVAYmzBZS9YlDp6PTSSDwa98vkD4QgVDDCAo84z5X1t5XyJQ62ImdLXx5NdIIfihey6xpum9/gRQ==", "dev": true }, - "node_modules/parserv2": { + "node_modules/parserapiv1": { "name": "@asyncapi/parser", - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.1.0.tgz", - "integrity": "sha512-78jjN3eW4ZmgJEa6Ap15lofzADCeItO4wHcAY2Jod3qLB1xf1zFDZQdtm3VSHYLeLhwoC1A33bAtzEf7M5P2bg==", + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.1.1.tgz", + "integrity": "sha512-FnJ5Du9iMu9MEb5mF90gF7z1ZkdnazisBsm3GHVFr7VaiF8luAoB+bklGYFwoMb+9QWKWr1099orY5VyXULAcQ==", "dependencies": { "@asyncapi/specs": "^5.1.0", "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", + "@stoplight/json": "^3.20.2", + "@stoplight/json-ref-readers": "^1.2.2", + "@stoplight/json-ref-resolver": "^3.1.5", + "@stoplight/spectral-core": "^1.16.1", + "@stoplight/spectral-functions": "^1.7.2", + "@stoplight/spectral-parsers": "^1.0.2", + "@stoplight/spectral-ref-resolver": "^1.0.3", + "@stoplight/types": "^13.12.0", + "@types/json-schema": "^7.0.11", + "@types/urijs": "^1.19.19", + "ajv": "^8.11.0", + "ajv-errors": "^3.0.0", + "ajv-formats": "^2.1.1", + "avsc": "^5.7.5", + "js-yaml": "^4.1.0", + "jsonpath-plus": "^7.2.0", + "node-fetch": "2.6.7", + "ramldt2jsonschema": "^1.2.3", + "webapi-parser": "^0.5.0" + } + }, + "node_modules/parserapiv1/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "node_modules/parserapiv1/node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/parserapiv1/node_modules/node-fetch": { + "version": "2.6.7", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", + "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/parserapiv1/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/parserapiv1/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/parserapiv1/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/parserapiv2": { + "name": "@asyncapi/parser", + "version": "3.0.0-next-major-spec.8", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.0.0-next-major-spec.8.tgz", + "integrity": "sha512-d8ebYM08BCsx3Q4AeLke6naU/NrcAXFEVpS6b3EWcKRdUDce+v0X5k9aDH+YXWCaQApEF28UzcxhlSOJvhIFgQ==", + "dependencies": { + "@asyncapi/specs": "^6.0.0-next-major-spec.9", + "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", "@stoplight/json-ref-resolver": "^3.1.5", "@stoplight/spectral-core": "^1.16.1", "@stoplight/spectral-functions": "^1.7.2", @@ -11166,12 +11256,20 @@ "webapi-parser": "^0.5.0" } }, - "node_modules/parserv2/node_modules/argparse": { + "node_modules/parserapiv2/node_modules/@asyncapi/specs": { + "version": "6.0.0-next-major-spec.13", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.0.0-next-major-spec.13.tgz", + "integrity": "sha512-mnGllHVaUscCHaDnYfLGo84KK81NcTmevVFQP94RusKM2SvtYkbBuC0nwQ6ie/PAEHQy+kn2PjrJlfwwm7VgEQ==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } + }, + "node_modules/parserapiv2/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, - "node_modules/parserv2/node_modules/js-yaml": { + "node_modules/parserapiv2/node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", @@ -11182,7 +11280,7 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/parserv2/node_modules/node-fetch": { + "node_modules/parserapiv2/node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", @@ -11201,17 +11299,17 @@ } } }, - "node_modules/parserv2/node_modules/tr46": { + "node_modules/parserapiv2/node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, - "node_modules/parserv2/node_modules/webidl-conversions": { + "node_modules/parserapiv2/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, - "node_modules/parserv2/node_modules/whatwg-url": { + "node_modules/parserapiv2/node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", @@ -11220,13 +11318,13 @@ "webidl-conversions": "^3.0.0" } }, - "node_modules/parserv3": { + "node_modules/parserapiv3": { "name": "@asyncapi/parser", - "version": "3.0.0-next-major-spec.3", - "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.0.0-next-major-spec.3.tgz", - "integrity": "sha512-LCrAQqJpGxraMyU2k1Nh1X6Q1dz7a/YhTRRFFrQHOEo+TUT/kRdoUkRDP++e58dO7h9MBN+/hZK5TaqE+/jQiw==", + "version": "3.0.0-next-major-spec.11", + "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-3.0.0-next-major-spec.11.tgz", + "integrity": "sha512-jJX2HGmeXykvJ1KfrYadeYbf0Dh4mDDvD5KNtf/SJGvVANdYRQrgCV14VlBMnv7kPVELuv8JaYEedYe6x4F8zA==", "dependencies": { - "@asyncapi/specs": "^6.0.0-next-major-spec.6", + "@asyncapi/specs": "^6.0.0-next-major-spec.9", "@openapi-contrib/openapi-schema-to-json-schema": "~3.2.0", "@stoplight/json-ref-resolver": "^3.1.5", "@stoplight/spectral-core": "^1.16.1", @@ -11245,20 +11343,20 @@ "webapi-parser": "^0.5.0" } }, - "node_modules/parserv3/node_modules/@asyncapi/specs": { - "version": "6.0.0-next-major-spec.7", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.0.0-next-major-spec.7.tgz", - "integrity": "sha512-rorau4qa1rjlIz4vGy3MuzQKSyKyJWuRa3DbFKopixDCjnAOIScVDc/M6/T8X9Ay+GQhebcYrbiPT4JUvWbFAA==", + "node_modules/parserapiv3/node_modules/@asyncapi/specs": { + "version": "6.0.0-next-major-spec.13", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.0.0-next-major-spec.13.tgz", + "integrity": "sha512-mnGllHVaUscCHaDnYfLGo84KK81NcTmevVFQP94RusKM2SvtYkbBuC0nwQ6ie/PAEHQy+kn2PjrJlfwwm7VgEQ==", "dependencies": { "@types/json-schema": "^7.0.11" } }, - "node_modules/parserv3/node_modules/argparse": { + "node_modules/parserapiv3/node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" }, - "node_modules/parserv3/node_modules/js-yaml": { + "node_modules/parserapiv3/node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", @@ -11269,7 +11367,7 @@ "js-yaml": "bin/js-yaml.js" } }, - "node_modules/parserv3/node_modules/node-fetch": { + "node_modules/parserapiv3/node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", @@ -11288,17 +11386,17 @@ } } }, - "node_modules/parserv3/node_modules/tr46": { + "node_modules/parserapiv3/node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" }, - "node_modules/parserv3/node_modules/webidl-conversions": { + "node_modules/parserapiv3/node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" }, - "node_modules/parserv3/node_modules/whatwg-url": { + "node_modules/parserapiv3/node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", @@ -14088,7 +14186,8 @@ "node_modules/uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", - "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==" + "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", + "dev": true }, "node_modules/uglify-js": { "version": "3.17.4", diff --git a/package.json b/package.json index f2e14f9d9..190abdf60 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@asyncapi/generator-react-sdk": "^1.0.2", "@asyncapi/parser": "^2.1.2", "@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", @@ -62,7 +62,6 @@ "js-yaml": "^3.13.1", "levenshtein-edit-distance": "^2.0.5", "loglevel": "^1.6.8", - "markdown-it": "^12.3.2", "minimatch": "^3.0.4", "node-fetch": "^2.6.0", "nunjucks": "^3.2.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'); });