From 125278e8a4fb51ff8f2dccd10ff526cca85e626f Mon Sep 17 00:00:00 2001 From: Jonas Lagoni Date: Tue, 14 Nov 2023 11:38:57 -1000 Subject: [PATCH] feat: enable AsyncAPI v3 (#1600) --- jest.config.js | 3 +- package-lock.json | 213 ++++++++++++++- package.json | 2 +- src/processors/AsyncAPIInputProcessor.ts | 36 +-- .../processors/AsyncAPIInputProcessor.spec.ts | 22 +- .../AsyncAPIInputProcessor/basic_v3.json | 34 +++ .../AsyncAPIInputProcessor.spec.ts.snap | 250 +++++++++++++++++- 7 files changed, 513 insertions(+), 47 deletions(-) create mode 100644 test/processors/AsyncAPIInputProcessor/basic_v3.json diff --git a/jest.config.js b/jest.config.js index de0ff25d0e..d644522f91 100644 --- a/jest.config.js +++ b/jest.config.js @@ -27,7 +27,8 @@ module.exports = { modulePathIgnorePatterns: [ '/examples/TEMPLATE', '/test/generators/template', - '/test/processors/TemplateInputProcessor.spec.ts' + '/test/processors/TemplateInputProcessor.spec.ts', + 'modelina-website' ], watchPathIgnorePatterns: ['/node_modules'] }; diff --git a/package-lock.json b/package-lock.json index 6a9e386955..3596bfd133 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.9", "@apidevtools/swagger-parser": "^10.0.3", - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "3.0.0-next-major-spec.8", "@smoya/multi-parser": "^4.0.0", "@swc/core": "^1.3.5", "@swc/jest": "^0.2.23", @@ -106,6 +106,63 @@ "avsc": "^5.7.6" } }, + "node_modules/@asyncapi/avro-schema-parser/node_modules/@asyncapi/parser": { + "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/@asyncapi/avro-schema-parser/node_modules/@asyncapi/specs": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-5.1.0.tgz", + "integrity": "sha512-yffhETqehkim43luMnPKOwzY0D0YtU4bKpORIXIaid6p5Y5kDLrMGJaEPkNieQp03HMjhjFrnUPtT8kvqe0+aQ==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } + }, + "node_modules/@asyncapi/avro-schema-parser/node_modules/@stoplight/json": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/@stoplight/json/-/json-3.21.0.tgz", + "integrity": "sha512-5O0apqJ/t4sIevXCO3SBN9AHCEKKR/Zb4gaj7wYe5863jme9g02Q0n/GhM7ZCALkL+vGPTe4ZzTETP8TFtsw3g==", + "dependencies": { + "@stoplight/ordered-object-literal": "^1.0.3", + "@stoplight/path": "^1.3.2", + "@stoplight/types": "^13.6.0", + "jsonc-parser": "~2.2.1", + "lodash": "^4.17.21", + "safe-stable-stringify": "^1.1" + }, + "engines": { + "node": ">=8.3.0" + } + }, + "node_modules/@asyncapi/avro-schema-parser/node_modules/safe-stable-stringify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-1.1.1.tgz", + "integrity": "sha512-ERq4hUjKDbJfE4+XtZLFPCDi8Vb1JqaxAPTxWFLBx8XcAlf9Bda/ZJdVezs/NAfsMQScyIlUMx+Yeu7P7rx5jw==" + }, "node_modules/@asyncapi/openapi-schema-parser": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@asyncapi/openapi-schema-parser/-/openapi-schema-parser-3.0.5.tgz", @@ -118,7 +175,7 @@ "ajv-formats": "^2.1.1" } }, - "node_modules/@asyncapi/parser": { + "node_modules/@asyncapi/openapi-schema-parser/node_modules/@asyncapi/parser": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@asyncapi/parser/-/parser-2.1.1.tgz", "integrity": "sha512-FnJ5Du9iMu9MEb5mF90gF7z1ZkdnazisBsm3GHVFr7VaiF8luAoB+bklGYFwoMb+9QWKWr1099orY5VyXULAcQ==", @@ -146,7 +203,7 @@ "webapi-parser": "^0.5.0" } }, - "node_modules/@asyncapi/parser/node_modules/@asyncapi/specs": { + "node_modules/@asyncapi/openapi-schema-parser/node_modules/@asyncapi/specs": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-5.1.0.tgz", "integrity": "sha512-yffhETqehkim43luMnPKOwzY0D0YtU4bKpORIXIaid6p5Y5kDLrMGJaEPkNieQp03HMjhjFrnUPtT8kvqe0+aQ==", @@ -154,7 +211,7 @@ "@types/json-schema": "^7.0.11" } }, - "node_modules/@asyncapi/parser/node_modules/@stoplight/json": { + "node_modules/@asyncapi/openapi-schema-parser/node_modules/@stoplight/json": { "version": "3.21.0", "resolved": "https://registry.npmjs.org/@stoplight/json/-/json-3.21.0.tgz", "integrity": "sha512-5O0apqJ/t4sIevXCO3SBN9AHCEKKR/Zb4gaj7wYe5863jme9g02Q0n/GhM7ZCALkL+vGPTe4ZzTETP8TFtsw3g==", @@ -170,11 +227,43 @@ "node": ">=8.3.0" } }, - "node_modules/@asyncapi/parser/node_modules/safe-stable-stringify": { + "node_modules/@asyncapi/openapi-schema-parser/node_modules/safe-stable-stringify": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-1.1.1.tgz", "integrity": "sha512-ERq4hUjKDbJfE4+XtZLFPCDi8Vb1JqaxAPTxWFLBx8XcAlf9Bda/ZJdVezs/NAfsMQScyIlUMx+Yeu7P7rx5jw==" }, + "node_modules/@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", + "@stoplight/spectral-parsers": "^1.0.2", + "@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/@asyncapi/parser/node_modules/@asyncapi/specs": { + "version": "6.0.0-next-major-spec.11", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-6.0.0-next-major-spec.11.tgz", + "integrity": "sha512-TR92zUaGQ5lZfc+f9L8yRCVqP7AVFvrMl2Ebr36ZGGC6cQwv80DZL/sbbgAWXzThAcTDXL1xsHUc0BpecHXoHw==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } + }, "node_modules/@asyncapi/parserV1": { "name": "@asyncapi/parser", "version": "1.18.1", @@ -241,6 +330,63 @@ "protocol-buffers-schema": "^3.6.0" } }, + "node_modules/@asyncapi/protobuf-schema-parser/node_modules/@asyncapi/parser": { + "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/@asyncapi/protobuf-schema-parser/node_modules/@asyncapi/specs": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-5.1.0.tgz", + "integrity": "sha512-yffhETqehkim43luMnPKOwzY0D0YtU4bKpORIXIaid6p5Y5kDLrMGJaEPkNieQp03HMjhjFrnUPtT8kvqe0+aQ==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } + }, + "node_modules/@asyncapi/protobuf-schema-parser/node_modules/@stoplight/json": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/@stoplight/json/-/json-3.21.0.tgz", + "integrity": "sha512-5O0apqJ/t4sIevXCO3SBN9AHCEKKR/Zb4gaj7wYe5863jme9g02Q0n/GhM7ZCALkL+vGPTe4ZzTETP8TFtsw3g==", + "dependencies": { + "@stoplight/ordered-object-literal": "^1.0.3", + "@stoplight/path": "^1.3.2", + "@stoplight/types": "^13.6.0", + "jsonc-parser": "~2.2.1", + "lodash": "^4.17.21", + "safe-stable-stringify": "^1.1" + }, + "engines": { + "node": ">=8.3.0" + } + }, + "node_modules/@asyncapi/protobuf-schema-parser/node_modules/safe-stable-stringify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-1.1.1.tgz", + "integrity": "sha512-ERq4hUjKDbJfE4+XtZLFPCDi8Vb1JqaxAPTxWFLBx8XcAlf9Bda/ZJdVezs/NAfsMQScyIlUMx+Yeu7P7rx5jw==" + }, "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", @@ -252,6 +398,63 @@ "webapi-parser": "^0.5.0" } }, + "node_modules/@asyncapi/raml-dt-schema-parser/node_modules/@asyncapi/parser": { + "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/@asyncapi/raml-dt-schema-parser/node_modules/@asyncapi/specs": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-5.1.0.tgz", + "integrity": "sha512-yffhETqehkim43luMnPKOwzY0D0YtU4bKpORIXIaid6p5Y5kDLrMGJaEPkNieQp03HMjhjFrnUPtT8kvqe0+aQ==", + "dependencies": { + "@types/json-schema": "^7.0.11" + } + }, + "node_modules/@asyncapi/raml-dt-schema-parser/node_modules/@stoplight/json": { + "version": "3.21.0", + "resolved": "https://registry.npmjs.org/@stoplight/json/-/json-3.21.0.tgz", + "integrity": "sha512-5O0apqJ/t4sIevXCO3SBN9AHCEKKR/Zb4gaj7wYe5863jme9g02Q0n/GhM7ZCALkL+vGPTe4ZzTETP8TFtsw3g==", + "dependencies": { + "@stoplight/ordered-object-literal": "^1.0.3", + "@stoplight/path": "^1.3.2", + "@stoplight/types": "^13.6.0", + "jsonc-parser": "~2.2.1", + "lodash": "^4.17.21", + "safe-stable-stringify": "^1.1" + }, + "engines": { + "node": ">=8.3.0" + } + }, + "node_modules/@asyncapi/raml-dt-schema-parser/node_modules/safe-stable-stringify": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/safe-stable-stringify/-/safe-stable-stringify-1.1.1.tgz", + "integrity": "sha512-ERq4hUjKDbJfE4+XtZLFPCDi8Vb1JqaxAPTxWFLBx8XcAlf9Bda/ZJdVezs/NAfsMQScyIlUMx+Yeu7P7rx5jw==" + }, "node_modules/@asyncapi/specs": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/@asyncapi/specs/-/specs-4.1.2.tgz", diff --git a/package.json b/package.json index 4eb836b813..861b6ffbfe 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@apidevtools/json-schema-ref-parser": "^9.0.9", "@apidevtools/swagger-parser": "^10.0.3", "@smoya/multi-parser": "^4.0.0", - "@asyncapi/parser": "^2.1.0", + "@asyncapi/parser": "3.0.0-next-major-spec.8", "@swc/core": "^1.3.5", "@swc/jest": "^0.2.23", "@types/node": "^20.3.3", diff --git a/src/processors/AsyncAPIInputProcessor.ts b/src/processors/AsyncAPIInputProcessor.ts index 0282486777..ffb1cfcdd5 100644 --- a/src/processors/AsyncAPIInputProcessor.ts +++ b/src/processors/AsyncAPIInputProcessor.ts @@ -11,7 +11,7 @@ import { import { AbstractInputProcessor } from './AbstractInputProcessor'; import { JsonSchemaInputProcessor } from './JsonSchemaInputProcessor'; -import { InputMetaModel, ProcessorOptions, UnionModel } from '../models'; +import { InputMetaModel, ProcessorOptions } from '../models'; import { Logger } from '../utils'; import { AsyncapiV2Schema } from '../models/AsyncapiV2Schema'; import { convertToMetaModel } from '../helpers'; @@ -29,7 +29,9 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { '2.3.0', '2.4.0', '2.5.0', - '2.6.0' + '2.6.0', + '2.6.0', + '3.0.0' ]; /** @@ -58,7 +60,7 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { doc = createAsyncAPIDocument(detailed); } else { const parserOptions = options?.asyncapi || {}; - const parser = NewParser(1, { + const parser = NewParser(2, { parserOptions, includeSchemaParsers: true }); @@ -67,7 +69,7 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { parserOptions ); if (document) { - doc = document as AsyncAPIDocumentInterface; + doc = document as unknown as AsyncAPIDocumentInterface; } else { const err = new Error( 'Input is not an correct AsyncAPI document so it cannot be processed.' @@ -83,21 +85,6 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { inputModel.originalInput = doc; const addToInputModel = (payload: AsyncAPISchemaInterface) => { - const id = payload.title() || payload.id(); - - for (const model of Object.values(inputModel.models)) { - if (model instanceof UnionModel) { - for (const union of model.union) { - if (union.name === id) { - Logger.warn( - `Model ${id} has already been added to the input model` - ); - return; - } - } - } - } - const schema = AsyncAPIInputProcessor.convertToInternalSchema(payload); const newCommonModel = JsonSchemaInputProcessor.convertSchemaToCommonModel(schema, options); @@ -158,13 +145,6 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { } } } - - for (const message of doc.messages()) { - const payload = message.payload(); - if (payload) { - addToInputModel(payload); - } - } } else { for (const message of doc.allMessages()) { const payload = message.payload(); @@ -337,7 +317,7 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { alreadyIteratedSchemas ); } else { - dependencies[String(dependencyName)] = dependency as string[]; + dependencies[String(dependencyName)] = dependency; } } convertedSchema.dependencies = dependencies; @@ -404,7 +384,7 @@ export class AsyncAPIInputProcessor extends AbstractInputProcessor { if (AsyncAPIInputProcessor.isFromParser(input)) { return input.version(); } - return input && input.asyncapi; + return input?.asyncapi; } /** diff --git a/test/processors/AsyncAPIInputProcessor.spec.ts b/test/processors/AsyncAPIInputProcessor.spec.ts index d509c82b36..b88d2343bf 100644 --- a/test/processors/AsyncAPIInputProcessor.spec.ts +++ b/test/processors/AsyncAPIInputProcessor.spec.ts @@ -7,6 +7,10 @@ const basicDocString = fs.readFileSync( path.resolve(__dirname, './AsyncAPIInputProcessor/basic.json'), 'utf8' ); +const basicV3DocString = fs.readFileSync( + path.resolve(__dirname, './AsyncAPIInputProcessor/basic_v3.json'), + 'utf8' +); const operationOneOf1DocString = fs.readFileSync( path.resolve(__dirname, './AsyncAPIInputProcessor/operation_oneof1.json'), 'utf8' @@ -58,14 +62,14 @@ describe('AsyncAPIInputProcessor', () => { const parsedObject = { asyncapi: '2.6.0' }; expect(processor.shouldProcess(parsedObject)).toEqual(true); }); + test('should be able to process AsyncAPI 3.x', () => { + const parsedObject = { asyncapi: '3.0.0' }; + expect(processor.shouldProcess(parsedObject)).toEqual(true); + }); test('should not be able to process unsupported AsyncAPI 2.x', () => { const parsedObject = { asyncapi: '2.123.0' }; expect(processor.shouldProcess(parsedObject)).toEqual(false); }); - test('should not be able to process AsyncAPI 3.x', () => { - const parsedObject = { asyncapi: '3.0.0' }; - expect(processor.shouldProcess(parsedObject)).toEqual(false); - }); }); describe('tryGetVersionOfDocument()', () => { const processor = new AsyncAPIInputProcessor(); @@ -80,6 +84,10 @@ describe('AsyncAPIInputProcessor', () => { const { document } = await parser.parse(basicDocString); expect(processor.tryGetVersionOfDocument(document)).toEqual('2.0.0'); }); + test('should be able to find AsyncAPI version for v3', () => { + const basicDoc = JSON.parse(basicV3DocString); + expect(processor.tryGetVersionOfDocument(basicDoc)).toEqual('3.0.0'); + }); }); describe('isFromParser()', () => { test('should be able to detect pure object', () => { @@ -115,6 +123,12 @@ describe('AsyncAPIInputProcessor', () => { const commonInputModel = await processor.process(basicDoc); expect(commonInputModel).toMatchSnapshot(); }); + test('should be able to process pure object for v3', async () => { + const basicDoc = JSON.parse(basicV3DocString); + const processor = new AsyncAPIInputProcessor(); + const commonInputModel = await processor.process(basicDoc); + expect(commonInputModel).toMatchSnapshot(); + }); test('should be able to process parsed objects', async () => { const { document } = await parser.parse(basicDocString); diff --git a/test/processors/AsyncAPIInputProcessor/basic_v3.json b/test/processors/AsyncAPIInputProcessor/basic_v3.json new file mode 100644 index 0000000000..1051bd8836 --- /dev/null +++ b/test/processors/AsyncAPIInputProcessor/basic_v3.json @@ -0,0 +1,34 @@ +{ + "asyncapi": "3.0.0", + "defaultContentType": "application/json", + "info": { + "title": "Signup service example (internal)", + "version": "0.1.0" + }, + "channels": { + "userSignedUp": { + "address": "/user/signedup", + "messages": { + "userSignUpMessage": { + "payload": { + "type": "object", + "properties": { + "email": { + "type": "string", + "format": "email" + } + } + } + } + } + } + }, + "operations": { + "userSignup": { + "action": "send", + "channel": { + "$ref": "#/channels/userSignedUp" + } + } + } +} \ No newline at end of file diff --git a/test/processors/__snapshots__/AsyncAPIInputProcessor.spec.ts.snap b/test/processors/__snapshots__/AsyncAPIInputProcessor.spec.ts.snap index 4f35c47b35..44d5ca5890 100644 --- a/test/processors/__snapshots__/AsyncAPIInputProcessor.spec.ts.snap +++ b/test/processors/__snapshots__/AsyncAPIInputProcessor.spec.ts.snap @@ -1510,7 +1510,7 @@ InputMetaModel { "title": "CloudEvent example", "version": "1.0.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "_meta": Object { @@ -1943,7 +1943,7 @@ InputMetaModel { "title": "CloudEvent example", "version": "1.0.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "semver": Object { @@ -3476,7 +3476,7 @@ InputMetaModel { "title": "CloudEvent example", "version": "1.0.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "_meta": Object { @@ -3909,7 +3909,7 @@ InputMetaModel { "title": "CloudEvent example", "version": "1.0.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "semver": Object { @@ -4027,7 +4027,7 @@ InputMetaModel { "title": "Signup service example (internal)", "version": "0.1.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "_meta": Object { @@ -4084,7 +4084,7 @@ InputMetaModel { "title": "Signup service example (internal)", "version": "0.1.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "semver": Object { @@ -4202,7 +4202,7 @@ InputMetaModel { "title": "Signup service example (internal)", "version": "0.1.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "_meta": Object { @@ -4259,7 +4259,7 @@ InputMetaModel { "title": "Signup service example (internal)", "version": "0.1.0", }, - "x-parser-api-version": 1, + "x-parser-api-version": 2, "x-parser-spec-parsed": true, }, "semver": Object { @@ -4276,3 +4276,237 @@ InputMetaModel { }, } `; + +exports[`AsyncAPIInputProcessor process() should be able to process pure object for v3 1`] = ` +InputMetaModel { + "models": Object { + "anonymous_schema_1": ObjectModel { + "name": "anonymous_schema_1", + "options": Object { + "isNullable": false, + }, + "originalInput": AsyncapiV2Schema { + "properties": Object { + "email": AsyncapiV2Schema { + "format": "email", + "type": "string", + "x-modelgen-inferred-name": "anonymous_schema_2", + "x-parser-schema-id": "", + }, + }, + "type": "object", + "x-modelgen-inferred-name": "anonymous_schema_1", + "x-parser-schema-id": "", + }, + "properties": Object { + "additionalProperties": ObjectPropertyModel { + "property": DictionaryModel { + "key": StringModel { + "name": "additionalProperties", + "options": Object { + "isNullable": false, + }, + "originalInput": Array [ + true, + ], + }, + "name": "additionalProperties", + "options": Object { + "isNullable": false, + }, + "originalInput": Array [ + true, + ], + "serializationType": "unwrap", + "value": AnyModel { + "name": "undefined", + "options": Object { + "isNullable": true, + }, + "originalInput": true, + }, + }, + "propertyName": "additionalProperties", + "required": false, + }, + "email": ObjectPropertyModel { + "property": StringModel { + "name": "anonymous_schema_2", + "options": Object { + "format": "email", + "isNullable": false, + }, + "originalInput": AsyncapiV2Schema { + "format": "email", + "type": "string", + "x-modelgen-inferred-name": "anonymous_schema_2", + "x-parser-schema-id": "", + }, + }, + "propertyName": "email", + "required": false, + }, + }, + }, + }, + "originalInput": AsyncAPIDocument { + "_json": Object { + "asyncapi": "3.0.0", + "channels": Object { + "userSignedUp": Object { + "address": "/user/signedup", + "messages": Object { + "userSignUpMessage": Object { + "payload": Object { + "properties": Object { + "email": Object { + "format": "email", + "type": "string", + "x-parser-schema-id": "", + }, + }, + "type": "object", + "x-parser-schema-id": "", + }, + "x-parser-message-name": "userSignUpMessage", + }, + }, + }, + }, + "defaultContentType": "application/json", + "info": Object { + "title": "Signup service example (internal)", + "version": "0.1.0", + }, + "operations": Object { + "userSignup": Object { + "action": "send", + "channel": Object { + "address": "/user/signedup", + "messages": Object { + "userSignUpMessage": Object { + "payload": Object { + "properties": Object { + "email": Object { + "format": "email", + "type": "string", + "x-parser-schema-id": "", + }, + }, + "type": "object", + "x-parser-schema-id": "", + }, + "x-parser-message-name": "userSignUpMessage", + }, + }, + }, + }, + }, + "x-parser-api-version": 2, + "x-parser-spec-parsed": true, + }, + "_meta": Object { + "asyncapi": Object { + "input": Object { + "asyncapi": "3.0.0", + "channels": Object { + "userSignedUp": Object { + "address": "/user/signedup", + "messages": Object { + "userSignUpMessage": Object { + "payload": Object { + "properties": Object { + "email": Object { + "format": "email", + "type": "string", + }, + }, + "type": "object", + }, + }, + }, + }, + }, + "defaultContentType": "application/json", + "info": Object { + "title": "Signup service example (internal)", + "version": "0.1.0", + }, + "operations": Object { + "userSignup": Object { + "action": "send", + "channel": Object { + "$ref": "#/channels/userSignedUp", + }, + }, + }, + }, + "parsed": Object { + "asyncapi": "3.0.0", + "channels": Object { + "userSignedUp": Object { + "address": "/user/signedup", + "messages": Object { + "userSignUpMessage": Object { + "payload": Object { + "properties": Object { + "email": Object { + "format": "email", + "type": "string", + "x-parser-schema-id": "", + }, + }, + "type": "object", + "x-parser-schema-id": "", + }, + "x-parser-message-name": "userSignUpMessage", + }, + }, + }, + }, + "defaultContentType": "application/json", + "info": Object { + "title": "Signup service example (internal)", + "version": "0.1.0", + }, + "operations": Object { + "userSignup": Object { + "action": "send", + "channel": Object { + "address": "/user/signedup", + "messages": Object { + "userSignUpMessage": Object { + "payload": Object { + "properties": Object { + "email": Object { + "format": "email", + "type": "string", + "x-parser-schema-id": "", + }, + }, + "type": "object", + "x-parser-schema-id": "", + }, + "x-parser-message-name": "userSignUpMessage", + }, + }, + }, + }, + }, + "x-parser-api-version": 2, + "x-parser-spec-parsed": true, + }, + "semver": Object { + "major": 3, + "minor": 0, + "patch": 0, + "rc": undefined, + "version": "3.0.0", + }, + "source": undefined, + }, + "pointer": "/", + }, + }, +} +`;