diff --git a/openapi.yaml b/openapi.yaml index cf47c94f..ccb8ca02 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -291,11 +291,6 @@ components: type: string description: Valid specification versions for the AsyncAPI document. enum: - - '1.0.0' - - '1.1.0' - - '1.2.0' - - '2.0.0-rc1' - - '2.0.0-rc2' - '2.0.0' - '2.1.0' - '2.2.0' diff --git a/package-lock.json b/package-lock.json index c2408490..03061d29 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,7 @@ "@asyncapi/parser": "^1.17.2", "@asyncapi/python-paho-template": "^0.2.13", "@asyncapi/raml-dt-schema-parser": "^2.0.1", - "@asyncapi/specs": "^3.2.1", + "@asyncapi/specs": "^4.0.1", "@asyncapi/ts-nats-template": "^0.10.1", "ajv": "^8.8.2", "ajv-formats": "^2.1.1", @@ -504,14 +504,6 @@ "webapi-parser": "^0.5.0" } }, - "node_modules/@asyncapi/dotnet-nats-template/node_modules/@asyncapi/specs": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", - "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", - "dependencies": { - "@types/json-schema": "^7.0.11" - } - }, "node_modules/@asyncapi/dotnet-nats-template/node_modules/jsonpath-plus": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", @@ -900,14 +892,6 @@ "tiny-merge-patch": "^0.1.2" } }, - "node_modules/@asyncapi/parser/node_modules/@asyncapi/specs": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", - "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", - "dependencies": { - "@types/json-schema": "^7.0.11" - } - }, "node_modules/@asyncapi/parser/node_modules/ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -972,6 +956,11 @@ "webapi-parser": "^0.5.0" } }, + "node_modules/@asyncapi/parserV2/node_modules/@asyncapi/specs": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", + "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + }, "node_modules/@asyncapi/parserV2/node_modules/jsonpath-plus": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", @@ -1074,9 +1063,12 @@ } }, "node_modules/@asyncapi/specs": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", - "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", + "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } }, "node_modules/@asyncapi/ts-nats-template": { "version": "0.10.1", @@ -4468,6 +4460,11 @@ "node": ">=12" } }, + "node_modules/@stoplight/spectral-rulesets/node_modules/@asyncapi/specs": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", + "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + }, "node_modules/@stoplight/spectral-runtime": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@stoplight/spectral-runtime/-/spectral-runtime-1.1.2.tgz", @@ -21174,14 +21171,6 @@ "webapi-parser": "^0.5.0" } }, - "@asyncapi/specs": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", - "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", - "requires": { - "@types/json-schema": "^7.0.11" - } - }, "jsonpath-plus": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", @@ -21527,14 +21516,6 @@ "tiny-merge-patch": "^0.1.2" }, "dependencies": { - "@asyncapi/specs": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", - "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", - "requires": { - "@types/json-schema": "^7.0.11" - } - }, "ajv": { "version": "6.12.6", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", @@ -21593,6 +21574,11 @@ "webapi-parser": "^0.5.0" }, "dependencies": { + "@asyncapi/specs": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", + "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + }, "jsonpath-plus": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", @@ -21690,9 +21676,12 @@ } }, "@asyncapi/specs": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", - "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.0.1.tgz", + "integrity": "sha512-3sKw49Y/TeKT/FO2YX/DlyOekytko5KFwNJ3zMPmai+pyhz3gux2p5zV5kGJRCwApI1gX0GJw6p15a6CZgg01w==", + "requires": { + "@types/json-schema": "^7.0.11" + } }, "@asyncapi/ts-nats-template": { "version": "0.10.1", @@ -24197,6 +24186,13 @@ "json-schema-traverse": "^1.0.0", "lodash": "~4.17.21", "tslib": "^2.3.0" + }, + "dependencies": { + "@asyncapi/specs": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-3.2.1.tgz", + "integrity": "sha512-FO+EteK+Gk3zwumrBw6frpp9cJ4oQL5++hBBpfM81w16e9KaiA4sKrzvQsvVjifoZZHNvVEX4D2zoz9i8CLccQ==" + } } }, "@stoplight/spectral-runtime": { diff --git a/package.json b/package.json index 3b03e1be..5ce8f524 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@asyncapi/parser": "^1.17.2", "@asyncapi/python-paho-template": "^0.2.13", "@asyncapi/raml-dt-schema-parser": "^2.0.1", - "@asyncapi/specs": "^3.2.1", + "@asyncapi/specs": "^4.0.1", "@asyncapi/ts-nats-template": "^0.10.1", "ajv": "^8.8.2", "ajv-formats": "^2.1.1", diff --git a/src/controllers/tests/convert.controller.test.ts b/src/controllers/tests/convert.controller.test.ts index 0acd6bbb..2fd6240f 100644 --- a/src/controllers/tests/convert.controller.test.ts +++ b/src/controllers/tests/convert.controller.test.ts @@ -15,6 +15,15 @@ const validJsonAsyncAPI2_0_0 = { channels: {} }; +const validJsonAsyncAPI2_1_0 = { + asyncapi: '2.1.0', + info: { + title: 'Super test', + version: '1.0.0' + }, + channels: {} +}; + const validYamlAsyncAPI2_3_0 = ` asyncapi: 2.4.0 info: @@ -67,14 +76,14 @@ describe('ConvertController', () => { return request(app.getServer()) .post('/v1/convert') .send({ - asyncapi: validJsonAsyncAPI2_0_0, - version: '1.2.0' + asyncapi: validJsonAsyncAPI2_1_0, + version: '2.0.0' }) .expect(422, { type: 'https://api.asyncapi.com/problem/internal-converter-error', title: 'Could not convert document', status: 422, - detail: 'Cannot downgrade from 2.0.0 to 1.2.0.', + detail: 'Cannot downgrade from 2.1.0 to 2.0.0.', }); }); diff --git a/src/services/convert.service.ts b/src/services/convert.service.ts index 5a00f47f..d53134c6 100644 --- a/src/services/convert.service.ts +++ b/src/services/convert.service.ts @@ -19,11 +19,11 @@ export class ConvertService { */ public async convert( spec: string | AsyncAPIDocument, - version: SpecsEnum = LAST_SPEC_VERSION, + version: SpecsEnum = LAST_SPEC_VERSION as SpecsEnum, language?: 'json' | 'yaml' | 'yml', ): Promise { if (version === 'latest') { - version = LAST_SPEC_VERSION; + version = LAST_SPEC_VERSION as SpecsEnum; } try { diff --git a/src/services/tests/convert.service.test.ts b/src/services/tests/convert.service.test.ts index 9bbf9c00..5a8adf9c 100644 --- a/src/services/tests/convert.service.test.ts +++ b/src/services/tests/convert.service.test.ts @@ -10,6 +10,15 @@ const validJsonAsyncAPI2_0_0 = { channels: {} }; +const validJsonAsyncAPI2_1_0 = { + asyncapi: '2.1.0', + info: { + title: 'Super test', + version: '1.0.0' + }, + channels: {} +}; + const validYamlAsyncAPI2_4_0 = ` asyncapi: 2.4.0 info: @@ -23,9 +32,9 @@ describe('ConvertService', () => { describe('.convert()', () => { it('should throw error that the converter cannot convert to a lower version', async () => { - let err: ProblemException; + let err: ProblemException | null = null; try { - await convertService.convert(validJsonAsyncAPI2_0_0, '1.2.0'); + await convertService.convert(validJsonAsyncAPI2_1_0, '2.0.0'); } catch (e) { err = e; } @@ -34,7 +43,7 @@ describe('ConvertService', () => { type: 'internal-converter-error', title: 'Could not convert document', status: 422, - detail: 'Cannot downgrade from 2.0.0 to 1.2.0.', + detail: 'Cannot downgrade from 2.1.0 to 2.0.0.', })); });