diff --git a/.eslintignore b/.eslintignore index 698542c..8dec2ff 100644 --- a/.eslintignore +++ b/.eslintignore @@ -7,3 +7,4 @@ tmp jest.config.js website playground/__gen__ +test/codegen/generators/*/output \ No newline at end of file diff --git a/.gitignore b/.gitignore index f96de6c..2bdc42f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ oclif.manifest.json dist coverage test/config/src/__gen__/ -playground \ No newline at end of file +playground +test/codegen/generators/*/output \ No newline at end of file diff --git a/src/codegen/generators/helpers/payloads.ts b/src/codegen/generators/helpers/payloads.ts index 4185c86..13f7b18 100644 --- a/src/codegen/generators/helpers/payloads.ts +++ b/src/codegen/generators/helpers/payloads.ts @@ -4,10 +4,10 @@ import { OutputModel } from '@asyncapi/modelina'; import {AsyncAPIDocumentInterface} from '@asyncapi/parser'; -import {PayloadRenderType} from '../../types'; +import {ChannelPayload, PayloadRenderType} from '../../types'; import {pascalCase} from '../typescript/utils'; import {findNameFromChannel} from '../../utils'; -type returnType = Record< +type ChannelReturnType = Record< string, {messageModel: OutputModel; messageType: string} >; @@ -17,61 +17,74 @@ export async function generateAsyncAPIPayloads( generator: (input: any) => Promise, generatorConfig: GeneratorType ): Promise> { - const returnType: returnType = {}; - for (const channel of asyncapiDocument.allChannels().all()) { - let schemaObj: any = { - type: 'object', - $schema: 'http://json-schema.org/draft-07/schema' - }; - const replyMessages = channel.messages().all(); - const messages = channel.messages().all(); - if (messages.length > 1) { - schemaObj.oneOf = []; - schemaObj['$id'] = pascalCase(`${findNameFromChannel(channel)}_Payload`); - for (const message of messages) { + const channelReturnType: ChannelReturnType = {}; + let otherModels: ChannelPayload[] = []; + if (asyncapiDocument.allChannels().all().length > 0) { + for (const channel of asyncapiDocument.allChannels().all()) { + let schemaObj: any = { + type: 'object', + $schema: 'http://json-schema.org/draft-07/schema' + }; + const replyMessages = channel.messages().all(); + const messages = channel.messages().all(); + if (messages.length > 1) { + schemaObj.oneOf = []; + schemaObj['$id'] = pascalCase(`${findNameFromChannel(channel)}_Payload`); + for (const message of messages) { + const schema = AsyncAPIInputProcessor.convertToInternalSchema( + message.payload() as any + ); + if (typeof schema === 'boolean') { + schemaObj.oneOf.push(schema); + } else { + schemaObj.oneOf.push({ + ...schema, + $id: message.id() + }); + } + } + } else if (messages.length === 1) { + const messagePayload = messages[0].payload(); const schema = AsyncAPIInputProcessor.convertToInternalSchema( - message.payload() as any + messagePayload as any ); + if (typeof schema === 'boolean') { - schemaObj.oneOf.push(schema); + schemaObj = schema; } else { - schemaObj.oneOf.push({ - ...schema, - 'x-modelgen-inferred-name': `${message.id()}` - }); + schemaObj = { + ...schemaObj, + ...(schema as any), + $id: messages[0].id() + }; } - } - } else if (messages.length === 1) { - const schema = AsyncAPIInputProcessor.convertToInternalSchema( - messages[0].payload() as any - ); - - if (typeof schema === 'boolean') { - schemaObj = schema; } else { - schemaObj = { - ...schemaObj, - ...(schema as any), - $id: `${messages[0].payload()?.id()}` - }; + continue; } - } else { - continue; - } - const models = await generator(schemaObj); - const messageModel = models[0].model; - let messageType = messageModel.type; - // Workaround from Modelina as rendering root payload model can create simple types and `.type` is no longer valid for what we use it for - if (!(messageModel instanceof ConstrainedObjectModel)) { - messageType = messageModel.name; + const models = await generator(schemaObj); + const messageModel = models[0].model; + let messageType = messageModel.type; + // Workaround from Modelina as rendering root payload model can create simple types and `.type` is no longer valid for what we use it for + if (!(messageModel instanceof ConstrainedObjectModel)) { + messageType = messageModel.name; + } + channelReturnType[channel.id()] = { + messageModel: models[0], + messageType + }; } - returnType[channel.id()] = { - messageModel: models[0], - messageType - }; + } else { + const generatedModels = await generator(asyncapiDocument); + otherModels = generatedModels.map((model) => { + return { + messageModel: model, + messageType: model.model.type + }; + }); } return { - channelModels: returnType, + channelModels: channelReturnType, + otherModels, generator: generatorConfig }; } diff --git a/src/codegen/generators/typescript/payloads.ts b/src/codegen/generators/typescript/payloads.ts index 7d0498f..7fb758b 100644 --- a/src/codegen/generators/typescript/payloads.ts +++ b/src/codegen/generators/typescript/payloads.ts @@ -1,9 +1,9 @@ /* eslint-disable security/detect-object-injection */ import { ConstrainedEnumModel, + ConstrainedMetaModel, ConstrainedObjectModel, ConstrainedReferenceModel, - ConstrainedStringModel, ConstrainedUnionModel, TS_COMMON_PRESET, TypeScriptFileGenerator @@ -14,6 +14,7 @@ import {generateAsyncAPIPayloads} from '../helpers/payloads'; import {z} from 'zod'; import {defaultCodegenTypescriptModelinaOptions} from './utils'; import {Logger} from '../../../LoggingInterface'; +import { TypeScriptRenderer } from '@asyncapi/modelina/lib/types/generators/typescript/TypeScriptRenderer'; export const zodTypeScriptPayloadGenerator = z.object({ id: z.string().optional().default('payloads-typescript'), @@ -22,13 +23,6 @@ export const zodTypeScriptPayloadGenerator = z.object({ outputPath: z.string().optional().default('src/__gen__/payloads'), serializationType: z.literal('json').optional().default('json'), language: z.literal('typescript').optional().default('typescript'), - model: z - .enum(['class', 'interface']) - .optional() - .default('class') - .describe( - 'By default all payloads are generated as class types, but in some cases interfaces might be more prudent.' - ), enum: z .enum(['enum', 'union']) .optional() @@ -41,7 +35,6 @@ export const zodTypeScriptPayloadGenerator = z.object({ .optional() .default('record') .describe('Which map type to use when a dictionary type is needed'), - moduleSystem: z.enum(['esm', 'cjs']).optional().default('esm').describe(''), useForJavaScript: z .boolean() .optional() @@ -78,6 +71,96 @@ export interface TypeScriptPayloadContext extends GenericCodegenContext { export type TypeScriptPayloadRenderType = PayloadRenderType; +/** + * Find the best possible discriminator value along side the properties using; + * - Enum value + * - Constant + * + */ +function findBestDiscriminatorOption(model: ConstrainedObjectModel, renderer: TypeScriptRenderer) { + //find first const or enum value since no explicit discriminator property found + const firstFound = Object.values(model.properties) + .map((property) => { + const enumModel = + property.property instanceof + ConstrainedReferenceModel && + property.property.ref instanceof ConstrainedEnumModel + ? property.property.ref + : undefined; + const constValue = property.property.options.const + ? property.property.options.const.value + : undefined; + return { + isEnumModel: enumModel !== undefined, + isConst: constValue !== undefined, + constValue, + enumModel, + property + }; + }) + .filter(({isConst, isEnumModel}) => { + return isConst || isEnumModel; + }); + if (firstFound.length > 1) { + const potentialProperties = firstFound + .map(({property}) => { + return property.propertyName; + }) + .join(', '); + Logger.warn( + `More then one property could be discriminator for union model ${model.name}, found property ${potentialProperties}` + ); + } + if (firstFound.length >= 1) { + const firstIsBest = firstFound[0]; + const discriminatorValue = + firstIsBest.property.unconstrainedPropertyName; + if (firstIsBest.isEnumModel) { + const enumModel = + firstIsBest.enumModel as ConstrainedEnumModel; + renderer.dependencyManager.addTypeScriptDependency( + `{${enumModel.type}}`, + `./${enumModel.type}` + ); + return { + objCheck: `if(json.${discriminatorValue} === ${enumModel.type}.${enumModel.values[0].key}) { + return ${model.name}.unmarshal(json); + }` + }; + } else if (firstIsBest.isConst) { + return { + objCheck: `if(json.${discriminatorValue} === ${firstIsBest.constValue}) { + return ${model.name}.unmarshal(json); + }` + }; + } + Logger.warn( + `Could not determine discriminator for ${model.name}, as part of ${model.name}, will not be able to serialize or deserialize messages with this payload` + ); + return {}; + } +} + +function findDiscriminatorChecks(model: ConstrainedMetaModel, renderer: TypeScriptRenderer) { + if ( + model instanceof ConstrainedReferenceModel && + model.ref instanceof ConstrainedObjectModel + ) { + const discriminatorValue = + model.options.discriminator?.type; + if (!discriminatorValue) { + return findBestDiscriminatorOption(model.ref, renderer); + } + + // Use discriminatorValue to figure out if we unmarshal it + return { + objCheck: `if(json.${model.options.discriminator?.discriminator} === ${discriminatorValue}}) { +return ${model.type}.unmarshal(json); +}` + }; + } + return {}; +} // eslint-disable-next-line sonarjs/cognitive-complexity export async function generateTypescriptPayload( context: TypeScriptPayloadContext @@ -100,87 +183,8 @@ export async function generateTypescriptPayload( type: { self({model, content, renderer}) { if (model instanceof ConstrainedUnionModel) { - const discriminatorChecks = model.union.map((unionModel) => { - if ( - unionModel instanceof ConstrainedReferenceModel && - unionModel.ref instanceof ConstrainedObjectModel - ) { - let discriminatorValue = - unionModel.options.discriminator?.type; - //find first const or enum value - if (!discriminatorValue) { - const firstFOund = Object.values(unionModel.ref.properties) - .map((property) => { - const enumModel = - property.property instanceof - ConstrainedReferenceModel && - property.property.ref instanceof ConstrainedEnumModel - ? property.property.ref - : undefined; - const constValue = property.property.options.const - ? property.property.options.const.value - : undefined; - return { - isEnumModel: enumModel !== undefined, - isConst: constValue !== undefined, - constValue, - enumModel, - property - }; - }) - .filter(({isConst, isEnumModel}) => { - return isConst || isEnumModel; - }); - if (firstFOund.length > 1) { - const potentialProperties = firstFOund - .map(({property}) => { - return property.propertyName; - }) - .join(', '); - Logger.warn( - `More then one property could be discriminator for union model ${unionModel.name}, found property ${potentialProperties}` - ); - } - if (firstFOund.length >= 1) { - const firstIsBest = firstFOund[0]; - discriminatorValue = - firstIsBest.property.unconstrainedPropertyName; - if (firstIsBest.isEnumModel) { - const enumModel = - firstIsBest.enumModel as ConstrainedEnumModel; - renderer.dependencyManager.addTypeScriptDependency( - `{${enumModel.type}}`, - `./${enumModel.type}` - ); - return { - objCheck: `if(json.${discriminatorValue} === ${enumModel.type}.${enumModel.values[0].key}) { - return ${unionModel.name}.unmarshal(json) -}` - }; - } else if (firstIsBest.isConst) { - return { - objCheck: `if(json.${discriminatorValue} === ${firstIsBest.constValue}) { - return ${unionModel.name}.unmarshal(json) -}` - }; - } - Logger.warn( - `Could not determine discriminator for ${unionModel.name}, as part of ${model.name}, will not be able to serialize or deserialize messages with this payload` - ); - return {}; - } - } else { - // Use discriminatorValue to figure out if we unmarshal it - return { - objCheck: `if(json.${unionModel.options.discriminator?.discriminator} === ${discriminatorValue}}) { -return ${unionModel.type}.unmarshal(json) -}` - }; - } - } else if (unionModel instanceof ConstrainedStringModel) { - return {strCheck: 'return json'}; - } - return {}; + const discriminatorChecks = model.union.map((model) => { + return findDiscriminatorChecks(model, renderer); }); const unmarshalChecks = model.union.map((unionModel) => { if ( @@ -191,42 +195,27 @@ return ${unionModel.type}.unmarshal(json) return payload.marshal(); }`; } - if (unionModel instanceof ConstrainedStringModel) { - return `if(typeof payload === 'string') { - return payload; -}`; - } - return ''; }); const hasObjValues = - discriminatorChecks.filter((value) => value.objCheck).length > - 1; - const hasStrValues = - discriminatorChecks.filter((value) => value.strCheck).length > + discriminatorChecks.filter((value) => value?.objCheck).length >= 1; return `${content}\n export function unmarshal(json: any): ${model.name} { ${ - hasObjValues && + hasObjValues ? `if(typeof json === 'object') { ${discriminatorChecks - .filter((value) => value.objCheck) - .map((value) => value.objCheck) + .filter((value) => value?.objCheck) + .map((value) => value?.objCheck) .join('\n ')} - }` - } - - ${ - hasStrValues && - `if(typeof json === 'string') { - return json; - }` + }` : '' } - throw new Error('Could not determine json input') + return JSON.parse(json); } export function marshal(payload: ${model.name}) { ${unmarshalChecks.join('\n')} + return JSON.stringify(payload); }`; } return content; @@ -236,8 +225,6 @@ export function marshal(payload: ${model.name}) { ], enumType: generator.enum, mapType: generator.map, - modelType: generator.model, - moduleSystem: generator.moduleSystem.toUpperCase() as any, rawPropertyNames: generator.rawPropertyNames, useJavascriptReservedKeywords: generator.useForJavaScript }); diff --git a/src/codegen/types.ts b/src/codegen/types.ts index cdda226..494b18b 100644 --- a/src/codegen/types.ts +++ b/src/codegen/types.ts @@ -66,6 +66,7 @@ export interface ChannelPayload { } export interface PayloadRenderType { channelModels: Record; + otherModels: ChannelPayload[]; generator: GeneratorType; } export interface SingleFunctionRenderType { diff --git a/test/codegen/generators/typescript/.gitignore b/test/codegen/generators/typescript/.gitignore new file mode 100644 index 0000000..6caf68a --- /dev/null +++ b/test/codegen/generators/typescript/.gitignore @@ -0,0 +1 @@ +output \ No newline at end of file diff --git a/test/codegen/generators/typescript/__snapshots__/payload.spec.ts.snap b/test/codegen/generators/typescript/__snapshots__/payload.spec.ts.snap new file mode 100644 index 0000000..ea84090 --- /dev/null +++ b/test/codegen/generators/typescript/__snapshots__/payload.spec.ts.snap @@ -0,0 +1,165 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`payloads typescript should work with basic AsyncAPI inputs 1`] = ` +"import {SimpleObject} from './SimpleObject'; +type UnionPayload = SimpleObject | boolean | string; + + +export function unmarshal(json: any): UnionPayload { + if(typeof json === 'object') { + if(json.type === 'SimpleObject') { + return SimpleObject.unmarshal(json); + } + } + return JSON.parse(json); +} +export function marshal(payload: UnionPayload) { + if(payload instanceof SimpleObject) { + return payload.marshal(); +} + + + return JSON.stringify(payload); +} +export { UnionPayload };" +`; + +exports[`payloads typescript should work with basic AsyncAPI inputs 2`] = ` +" +class SimpleObject2 { + private _displayName?: string; + private _email?: string; + private _additionalProperties?: Record; + + constructor(input: { + displayName?: string, + email?: string, + additionalProperties?: Record, + }) { + this._displayName = input.displayName; + this._email = input.email; + this._additionalProperties = input.additionalProperties; + } + + get displayName(): string | undefined { return this._displayName; } + set displayName(displayName: string | undefined) { this._displayName = displayName; } + + get email(): string | undefined { return this._email; } + set email(email: string | undefined) { this._email = email; } + + get additionalProperties(): Record | undefined { return this._additionalProperties; } + set additionalProperties(additionalProperties: Record | undefined) { this._additionalProperties = additionalProperties; } + + public marshal() : string { + let json = '{' + if(this.displayName !== undefined) { + json += \`"displayName": \${typeof this.displayName === 'number' || typeof this.displayName === 'boolean' ? this.displayName : JSON.stringify(this.displayName)},\`; + } + if(this.email !== undefined) { + json += \`"email": \${typeof this.email === 'number' || typeof this.email === 'boolean' ? this.email : JSON.stringify(this.email)},\`; + } + if(this.additionalProperties !== undefined) { + for (const [key, value] of this.additionalProperties.entries()) { + //Only unwrap those that are not already a property in the JSON object + if(["displayName","email","additionalProperties"].includes(String(key))) continue; + json += \`"\${key}": \${typeof value === 'number' || typeof value === 'boolean' ? value : JSON.stringify(value)},\`; + } + } + //Remove potential last comma + return \`\${json.charAt(json.length-1) === ',' ? json.slice(0, json.length-1) : json}}\`; + } + + public static unmarshal(json: string | object): SimpleObject2 { + const obj = typeof json === "object" ? json : JSON.parse(json); + const instance = new SimpleObject2({} as any); + + if (obj["displayName"] !== undefined) { + instance.displayName = obj["displayName"]; + } + if (obj["email"] !== undefined) { + instance.email = obj["email"]; + } + + instance.additionalProperties = new Map(); + const propsToCheck = Object.entries(obj).filter((([key,]) => {return !["displayName","email","additionalProperties"].includes(key);})); + for (const [key, value] of propsToCheck) { + instance.additionalProperties.set(key, value as any); + } + return instance; + } +} +export { SimpleObject2 };" +`; + +exports[`payloads typescript should work with no channels 1`] = ` +" +class AnonymousSchema_1 { + private _type?: 'SimpleObject' = 'SimpleObject'; + private _displayName?: string; + private _email?: string; + private _additionalProperties?: Record; + + constructor(input: { + displayName?: string, + email?: string, + additionalProperties?: Record, + }) { + this._displayName = input.displayName; + this._email = input.email; + this._additionalProperties = input.additionalProperties; + } + + get type(): 'SimpleObject' | undefined { return this._type; } + + get displayName(): string | undefined { return this._displayName; } + set displayName(displayName: string | undefined) { this._displayName = displayName; } + + get email(): string | undefined { return this._email; } + set email(email: string | undefined) { this._email = email; } + + get additionalProperties(): Record | undefined { return this._additionalProperties; } + set additionalProperties(additionalProperties: Record | undefined) { this._additionalProperties = additionalProperties; } + + public marshal() : string { + let json = '{' + if(this.type !== undefined) { + json += \`"type": \${typeof this.type === 'number' || typeof this.type === 'boolean' ? this.type : JSON.stringify(this.type)},\`; + } + if(this.displayName !== undefined) { + json += \`"displayName": \${typeof this.displayName === 'number' || typeof this.displayName === 'boolean' ? this.displayName : JSON.stringify(this.displayName)},\`; + } + if(this.email !== undefined) { + json += \`"email": \${typeof this.email === 'number' || typeof this.email === 'boolean' ? this.email : JSON.stringify(this.email)},\`; + } + if(this.additionalProperties !== undefined) { + for (const [key, value] of this.additionalProperties.entries()) { + //Only unwrap those that are not already a property in the JSON object + if(["type","displayName","email","additionalProperties"].includes(String(key))) continue; + json += \`"\${key}": \${typeof value === 'number' || typeof value === 'boolean' ? value : JSON.stringify(value)},\`; + } + } + //Remove potential last comma + return \`\${json.charAt(json.length-1) === ',' ? json.slice(0, json.length-1) : json}}\`; + } + + public static unmarshal(json: string | object): AnonymousSchema_1 { + const obj = typeof json === "object" ? json : JSON.parse(json); + const instance = new AnonymousSchema_1({} as any); + + if (obj["displayName"] !== undefined) { + instance.displayName = obj["displayName"]; + } + if (obj["email"] !== undefined) { + instance.email = obj["email"]; + } + + instance.additionalProperties = new Map(); + const propsToCheck = Object.entries(obj).filter((([key,]) => {return !["type","displayName","email","additionalProperties"].includes(key);})); + for (const [key, value] of propsToCheck) { + instance.additionalProperties.set(key, value as any); + } + return instance; + } +} +export { AnonymousSchema_1 };" +`; diff --git a/test/codegen/generators/typescript/payload.spec.ts b/test/codegen/generators/typescript/payload.spec.ts new file mode 100644 index 0000000..461f720 --- /dev/null +++ b/test/codegen/generators/typescript/payload.spec.ts @@ -0,0 +1,54 @@ +import path from "node:path"; +import { generateTypescriptPayload } from "../../../../src/codegen/generators"; +import { loadAsyncapi } from "../../../helpers"; + +describe('payloads', () => { + describe('typescript', () => { + it('should work with basic AsyncAPI inputs', async () => { + const parsedAsyncAPIDocument = await loadAsyncapi(path.resolve(__dirname, '../../../configs/payload.yaml')); + + const renderedContent = await generateTypescriptPayload({ + generator: { + enum: 'enum', + map: 'record', + rawPropertyNames: false, + serializationType: 'json', + useForJavaScript: false, + outputPath: path.resolve(__dirname, './output'), + preset: 'payloads', + language: 'typescript', + dependencies: [], + id: 'test' + }, + inputType: 'asyncapi', + asyncapiDocument: parsedAsyncAPIDocument, + dependencyOutputs: { } + }); + expect(renderedContent.channelModels['union'].messageModel.result).toMatchSnapshot(); + expect(renderedContent.channelModels['simple'].messageModel.result).toMatchSnapshot(); + }); + it('should work with no channels', async () => { + const parsedAsyncAPIDocument = await loadAsyncapi(path.resolve(__dirname, '../../../configs/payload-no-channels.yaml')); + + const renderedContent = await generateTypescriptPayload({ + generator: { + enum: 'enum', + map: 'record', + rawPropertyNames: false, + serializationType: 'json', + useForJavaScript: false, + outputPath: path.resolve(__dirname, './output'), + preset: 'payloads', + language: 'typescript', + dependencies: [], + id: 'test' + }, + inputType: 'asyncapi', + asyncapiDocument: parsedAsyncAPIDocument, + dependencyOutputs: { } + }); + expect(renderedContent.otherModels.length).toEqual(1); + expect(renderedContent.otherModels[0].messageModel.result).toMatchSnapshot(); + }); + }); +}); diff --git a/test/configs/payload-no-channels.yaml b/test/configs/payload-no-channels.yaml new file mode 100644 index 0000000..327eddd --- /dev/null +++ b/test/configs/payload-no-channels.yaml @@ -0,0 +1,20 @@ +asyncapi: 3.0.0 +info: + title: Account Service + version: 1.0.0 + description: This service is in charge of processing user signups +components: + messages: + SimpleObject: + payload: + type: object + properties: + type: + const: 'SimpleObject' + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user \ No newline at end of file diff --git a/test/configs/payload.yaml b/test/configs/payload.yaml new file mode 100644 index 0000000..bdfe2fd --- /dev/null +++ b/test/configs/payload.yaml @@ -0,0 +1,40 @@ +asyncapi: 3.0.0 +info: + title: Account Service + version: 1.0.0 + description: This service is in charge of processing user signups +channels: + simple: + messages: + SimpleObject2: + payload: + type: object + properties: + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + union: + messages: + SimpleObject: + payload: + type: object + properties: + type: + const: 'SimpleObject' + displayName: + type: string + description: Name of the user + email: + type: string + format: email + description: Email of the user + Boolean: + payload: + type: 'boolean' + String: + payload: + type: 'string' \ No newline at end of file diff --git a/test/runtime/typescript/test/nats-channels.spec.ts b/test/runtime/typescript/test/nats-channels.spec.ts index cc6db3e..7f016af 100644 --- a/test/runtime/typescript/test/nats-channels.spec.ts +++ b/test/runtime/typescript/test/nats-channels.spec.ts @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { AckPolicy, DeliverPolicy, JetStreamClient, JetStreamManager, NatsConnection, ReplayPolicy, connect, ConsumerOpts } from "nats"; import { Protocols } from '../src/channels/index'; -import { UserSignedUpPayload } from '../src/payloads/UserSignedUpPayload'; +import { UserSignedUp } from '../src/payloads/UserSignedUp'; import { UserSignedupParameters } from '../src/parameters/UserSignedupParameters'; const { nats } = Protocols; const { @@ -10,7 +10,7 @@ const { jest.setTimeout(10000) describe('channels', () => { - const testMessage = new UserSignedUpPayload({displayName: 'test', email: 'test@test.dk'}); + const testMessage = new UserSignedUp({displayName: 'test', email: 'test@test.dk'}); describe('with parameters', () => { const testParameters = new UserSignedupParameters({myParameter: 'test', enumParameter: 'asyncapi'}); describe('NATS', () => { diff --git a/test/runtime/typescript/test/payloads.spec.ts b/test/runtime/typescript/test/payloads.spec.ts index 22cd72c..6d95802 100644 --- a/test/runtime/typescript/test/payloads.spec.ts +++ b/test/runtime/typescript/test/payloads.spec.ts @@ -1,8 +1,8 @@ -import { UserSignedUpPayload } from '../src/payloads/UserSignedUpPayload'; +import { UserSignedUp } from '../src/payloads/UserSignedUp'; describe('payloads', () => { describe('should be able to serialize and deserialize the model', () => { - const testObject = new UserSignedUpPayload({ + const testObject = new UserSignedUp({ email: 'emailTest', displayName: 'displayNameTest' }); @@ -12,7 +12,7 @@ describe('payloads', () => { }); test('be able to serialize model and turning it back to a model with the same values', () => { const serialized = testObject.marshal(); - const newAddress = UserSignedUpPayload.unmarshal(serialized); + const newAddress = UserSignedUp.unmarshal(serialized); expect(serialized).toEqual(newAddress.marshal()); }); });