Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove messageId() #889

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/models/message-trait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export interface MessageTraitInterface extends BaseModel, BindingsMixinInterface
hasSchemaFormat(): boolean;
schemaFormat(): string | undefined;
hasMessageId(): boolean;
messageId(): string | undefined;
hasCorrelationId(): boolean;
correlationId(): CorrelationIdInterface | undefined;
hasContentType(): boolean;
Expand Down
6 changes: 1 addition & 5 deletions src/models/v2/message-trait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type { v2 } from '../../spec-types';

export class MessageTrait<J extends v2.MessageTraitObject = v2.MessageTraitObject> extends BaseModel<J, { id: string }> implements MessageTraitInterface {
id(): string {
return this.messageId() || this._meta.id || this.json(xParserMessageName) as string;
return this._json.messageId || this._meta.id || this.json(xParserMessageName) as string;
}

hasSchemaFormat(): boolean {
Expand All @@ -35,10 +35,6 @@ export class MessageTrait<J extends v2.MessageTraitObject = v2.MessageTraitObjec
hasMessageId(): boolean {
return !!this._json.messageId;
}

messageId(): string | undefined {
return this._json.messageId;
}

hasCorrelationId(): boolean {
return !!this._json.correlationId;
Expand Down
8 changes: 2 additions & 6 deletions src/models/v3/message-trait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import type { v3 } from '../../spec-types';

export class MessageTrait<J extends v3.MessageTraitObject = v3.MessageTraitObject> extends CoreModel<J, { id: string }> implements MessageTraitInterface {
id(): string {
return this.messageId() || this._meta.id || this.extensions().get(xParserMessageName)?.value<string>() as string;
return this._meta.id || this.extensions().get(xParserMessageName)?.value<string>() as string;
}

hasMessageId(): boolean {
return !!this._json.messageId;
return false;
}
jonaslagoni marked this conversation as resolved.
Show resolved Hide resolved

hasSchemaFormat(): boolean {
Expand All @@ -29,10 +29,6 @@ export class MessageTrait<J extends v3.MessageTraitObject = v3.MessageTraitObjec
schemaFormat(): string | undefined {
return undefined;
}

messageId(): string | undefined {
return this._json.messageId;
}

hasCorrelationId(): boolean {
return !!this._json.correlationId;
Expand Down
1 change: 0 additions & 1 deletion src/spec-types/v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ export interface MessageObject extends MessageTraitObject, SpecificationExtensio
}

export interface MessageTraitObject extends SpecificationExtensions {
messageId?: string;
headers?: MultiFormatSchemaObject;
correlationId?: CorrelationIDObject | ReferenceObject;
contentType?: string;
Expand Down
20 changes: 10 additions & 10 deletions test/custom-operations/apply-traits-v3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('custom operations - apply traits v3', function() {
someMessage: {
traits: [
{
messageId: 'traitMessageId',
summary: 'some summary',
description: 'some description'
},
{
Expand All @@ -89,11 +89,11 @@ describe('custom operations - apply traits v3', function() {
someChannel2: {
messages: {
someMessage: {
messageId: 'rootMessageId',
summary: 'root summary',
description: 'root description',
traits: [
{
messageId: 'traitMessageId',
summary: 'some summary',
description: 'some description'
},
{
Expand All @@ -112,11 +112,11 @@ describe('custom operations - apply traits v3', function() {

const message1 = v3Document?.json()?.channels?.someChannel1?.messages?.someMessage;
delete (message1 as v3.MessageObject)?.traits;
expect(message1).toEqual({ messageId: 'traitMessageId', description: 'another description', 'x-parser-message-name': 'traitMessageId' });
expect(message1).toEqual({ summary: 'some summary', description: 'another description', 'x-parser-message-name': 'someMessage' });

const message2 = v3Document?.json()?.channels?.someChannel2?.messages?.someMessage;
delete (message2 as v3.MessageObject)?.traits;
expect(message2).toEqual({ messageId: 'rootMessageId', description: 'root description', 'x-parser-message-name': 'rootMessageId' });
expect(message2).toEqual({ summary: 'root summary', description: 'root description', 'x-parser-message-name': 'someMessage' });
});

it('should apply traits to messages (components)', async function() {
Expand All @@ -131,7 +131,7 @@ describe('custom operations - apply traits v3', function() {
someMessage1: {
traits: [
{
messageId: 'traitMessageId',
summary: 'some summary',
description: 'some description'
},
{
Expand All @@ -140,11 +140,11 @@ describe('custom operations - apply traits v3', function() {
]
},
someMessage2: {
messageId: 'rootMessageId',
summary: 'root summary',
description: 'root description',
traits: [
{
messageId: 'traitMessageId',
summary: 'some summary',
description: 'some description'
},
{
Expand All @@ -162,10 +162,10 @@ describe('custom operations - apply traits v3', function() {

const message1 = v3Document?.json()?.components?.messages?.someMessage1;
delete (message1 as v3.MessageObject)?.traits;
expect(message1).toEqual({ messageId: 'traitMessageId', description: 'another description', 'x-parser-message-name': 'traitMessageId' });
expect(message1).toEqual({ summary: 'some summary', description: 'another description', 'x-parser-message-name': 'someMessage1' });

const message2 = v3Document?.json()?.components?.messages?.someMessage2;
delete (message2 as v3.MessageObject)?.traits;
expect(message2).toEqual({ messageId: 'rootMessageId', description: 'root description', 'x-parser-message-name': 'rootMessageId' });
expect(message2).toEqual({ summary: 'root summary', description: 'root description', 'x-parser-message-name': 'someMessage2' });
});
});
6 changes: 3 additions & 3 deletions test/models/v2/channel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Channel model', function() {
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual((doc as any).publish.message.messageId);
expect(d.messages().all()[0].id()).toEqual((doc as any).publish.message.messageId);
});

it('should return collection of messages - oneOf message', function() {
Expand All @@ -109,9 +109,9 @@ describe('Channel model', function() {
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(2);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual((doc as any).subscribe.message.oneOf[0].messageId);
expect(d.messages().all()[0].id()).toEqual((doc as any).subscribe.message.oneOf[0].messageId);
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].messageId()).toEqual((doc as any).subscribe.message.oneOf[1].messageId);
expect(d.messages().all()[1].id()).toEqual((doc as any).subscribe.message.oneOf[1].messageId);
});

it('should return collection of messages - single message and oneOf', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/models/v2/message-trait.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ describe('MessageTrait model', function() {
it('should return the value', function() {
const doc = { messageId: '...' };
const d = new MessageTrait(doc);
expect(d.messageId()).toEqual(doc.messageId);
expect(d.id()).toEqual(doc.messageId);
});

it('should return undefined when there is no value', function() {
const doc = {};
const d = new MessageTrait(doc);
expect(d.messageId()).toBeUndefined();
expect(d.id()).toBeUndefined();
});
});

Expand Down
14 changes: 7 additions & 7 deletions test/models/v2/server.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('Server Model', function () {
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('1');
expect(d.messages().all()[0].id()).toEqual('1');
});

it('should return collection of messages - multiple channels', function() {
Expand All @@ -153,11 +153,11 @@ describe('Server Model', function () {
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(3);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('1');
expect(d.messages().all()[0].id()).toEqual('1');
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].messageId()).toEqual('2');
expect(d.messages().all()[1].id()).toEqual('2');
expect(d.messages().all()[2]).toBeInstanceOf(Message);
expect(d.messages().all()[2].messageId()).toEqual('3');
expect(d.messages().all()[2].id()).toEqual('3');
});

it('should return collection of messages - server available only in particular channel', function() {
Expand All @@ -166,11 +166,11 @@ describe('Server Model', function () {
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(3);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('1');
expect(d.messages().all()[0].id()).toEqual('1');
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].messageId()).toEqual('2');
expect(d.messages().all()[1].id()).toEqual('2');
expect(d.messages().all()[2]).toBeInstanceOf(Message);
expect(d.messages().all()[2].messageId()).toEqual('3');
expect(d.messages().all()[2].id()).toEqual('3');
});
});

Expand Down
10 changes: 5 additions & 5 deletions test/models/v3/channel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,26 @@ describe('Channel model', function() {

describe('.messages()', function() {
it('should return collection of messages - single message', function() {
const doc = serializeInput<v3.ChannelObject>({ messages: { someMessage: { messageId: 'messageId' } } });
const doc = serializeInput<v3.ChannelObject>({ messages: { someMessage: {} } });
const d = new Channel(doc);
const msg = doc.messages?.['someMessage'] as v3.MessageObject;
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual(msg?.messageId);
expect(d.messages().all()[0].id()).toEqual('someMessage');
});

it('should return collection of messages - more than one messages', function() {
const doc = serializeInput<v3.ChannelObject>({ messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } });
const doc = serializeInput<v3.ChannelObject>({ messages: { someMessage1: {}, someMessage2: {} } });
const d = new Channel(doc);
const msg1 = doc.messages?.['someMessage1'] as v3.MessageObject;
const msg2 = doc.messages?.['someMessage2'] as v3.MessageObject;
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(2);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].id()).toEqual(msg1.messageId);
expect(d.messages().all()[0].id()).toEqual('someMessage1');
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].id()).toEqual(msg2.messageId);
expect(d.messages().all()[1].id()).toEqual('someMessage2');
});
});

Expand Down
28 changes: 4 additions & 24 deletions test/models/v3/message-trait.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ describe('MessageTrait model', function() {
const d = new MessageTrait(doc, { asyncapi: {} as any, pointer: '', id: 'trait' });
expect(d.id()).toEqual('trait');
});

it('should reuse messageId', function() {
const doc = { messageId: '...' };
const d = new MessageTrait(doc);
expect(d.id()).toEqual(doc.messageId);
});
});

describe('.schemaFormat()', function() {
Expand All @@ -38,30 +32,16 @@ describe('MessageTrait model', function() {
});

describe('.hasMessageId()', function() {
it('should return true when there is a value', function() {
const doc = { messageId: '...' };
const d = new MessageTrait(doc);
expect(d.hasMessageId()).toEqual(true);
});

it('should return false when there is no value', function() {
it('should return false when there is a value', function() {
const doc = {};
const d = new MessageTrait(doc);
const d = new MessageTrait(doc, { asyncapi: {} as any, pointer: '', id: 'message' });
expect(d.hasMessageId()).toEqual(false);
});
});

describe('.messageId()', function() {
it('should return the value', function() {
const doc = { messageId: '...' };
const d = new MessageTrait(doc);
expect(d.messageId()).toEqual(doc.messageId);
});

it('should return undefined when there is no value', function() {
it('should return false when there is no value', function() {
const doc = {};
const d = new MessageTrait(doc);
expect(d.messageId()).toBeUndefined();
expect(d.hasMessageId()).toEqual(false);
});
});

Expand Down
6 changes: 0 additions & 6 deletions test/models/v3/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ describe('Message model', function() {
const d = new Message(doc, { asyncapi: {} as any, pointer: '', id: 'message' });
expect(d.id()).toEqual('message');
});

it('should reuse messageId', function() {
const doc = { messageId: '...' };
const d = new Message(doc);
expect(d.id()).toEqual(doc.messageId);
});
});

describe('.schemaFormat() + .hasSchemaFormat()', function() {
Expand Down
8 changes: 4 additions & 4 deletions test/models/v3/operation-reply.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,20 @@ describe('OperationReply model', function() {

describe('.messages()', function() {
it('should return collection of messages - single message', function() {
const d = new OperationReply({ messages: { someMessage: { messageId: 'messageId' } } });
const d = new OperationReply({ messages: { someMessage: {} } });
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
});

it('should return collection of messages - more than one messages', function() {
const d = new OperationReply({ messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } });
const d = new OperationReply({ messages: { someMessage1: {}, someMessage2: {} } });
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(2);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('messageId1');
expect(d.messages().all()[0].id()).toEqual('someMessage1');
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].messageId()).toEqual('messageId2');
expect(d.messages().all()[1].id()).toEqual('someMessage2');
});

it('should return undefined if address is not present', function() {
Expand Down
12 changes: 6 additions & 6 deletions test/models/v3/operation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,31 @@ describe('Operation model', function() {

describe('.messages()', function() {
it('should return collection of messages - single message', function() {
const channel = { messages: { someMessage: { messageId: 'messageId' } } };
const channel = { messages: { someMessage: { summary: 'summary' } } };
const d = new Operation({ action: 'send', channel }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' });
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
});

it('should return collection of messages - more than one messages', function() {
const channel = { messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } };
const channel = { messages: { someMessage1: { summary: 'summary1' }, someMessage2: { summary: 'summary2' } } };
const d = new Operation({ action: 'send', channel }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' });
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(2);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('messageId1');
expect(d.messages().all()[0].summary()).toEqual('summary1');
expect(d.messages().all()[1]).toBeInstanceOf(Message);
expect(d.messages().all()[1].messageId()).toEqual('messageId2');
expect(d.messages().all()[1].summary()).toEqual('summary2');
});

it('should return collection of messages - defined message on operation level', function() {
const channel = { messages: { someMessage1: { messageId: 'messageId1' }, someMessage2: { messageId: 'messageId2' } } };
const channel = { messages: { someMessage1: { summary: 'summary1' }, someMessage2: { summary: 'summary2' } } };
const d = new Operation({ action: 'send', channel, messages: [channel.messages.someMessage1] }, { asyncapi: { parsed: { channels: { someChannel: channel } } } as any, pointer: '', id: 'operation' });
expect(d.messages()).toBeInstanceOf(Messages);
expect(d.messages().all()).toHaveLength(1);
expect(d.messages().all()[0]).toBeInstanceOf(Message);
expect(d.messages().all()[0].messageId()).toEqual('messageId1');
expect(d.messages().all()[0].summary()).toEqual('summary1');
});

it('should return undefined when there is no value', function() {
Expand Down
Loading