Skip to content
This repository was archived by the owner on Jun 18, 2023. It is now read-only.

Commit 624b6a6

Browse files
timonbackstavshamir
authored andcommitted
GH-83: ui: Show publisher and consumer for same topic
When a publisher AND subscriber is defined for the same channel, both are shown. To simplify, the publisher and subscriber are shown as individual entries in the UI and are not merged together.
1 parent 959dd4c commit 624b6a6

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/app/shared/asyncapi.service.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ interface ServerAsyncApi {
2222
[key: string]: {
2323
description?: string;
2424
subscribe?: {
25-
message: Message;
25+
message: Message | { oneOf: Message[] };
2626
bindings?: any;
2727
};
2828
publish?: {
29-
message: Message;
29+
message: Message | { oneOf: Message[] };
3030
bindings?: any;
3131
};
3232
};
@@ -82,43 +82,47 @@ export class AsyncApiService {
8282
};
8383
}
8484

85-
private mapServers(servers: { [key: string]: Server }): Map<string, Server> {
85+
private mapServers(servers: ServerAsyncApi["servers"]): Map<string, Server> {
8686
const s = new Map<string, Server>();
8787
Object.entries(servers).forEach(([k, v]) => s.set(k, v));
8888
return s;
8989
}
9090

91-
private mapChannels(channels: {
92-
[key: string]: {
93-
description?: string;
94-
subscribe?: {
95-
message: Message;
96-
bindings?: any;
97-
};
98-
publish?: {
99-
message: Message | { oneOf: Message[] };
100-
bindings?: any;
101-
};
102-
}
103-
}): Channel[] {
91+
private mapChannels(channels: ServerAsyncApi["channels"]): Channel[] {
10492
const s = new Array<Channel>();
10593
Object.entries(channels).forEach(([k, v]) => {
106-
let operation = v.publish ? v.publish : v.subscribe;
107-
let isSubscribe = !!v.subscribe;
94+
const subscriberChannels = this.mapChannel(k, v.description, v.subscribe, " consumer")
95+
subscriberChannels.forEach(channel => s.push(channel))
10896

109-
let messages: Message[] = 'oneOf' in operation.message ? operation.message.oneOf : [operation.message];
110-
messages.forEach(message => s.push({
111-
name: k,
112-
description: v.description,
113-
operation: this.mapOperation(isSubscribe, message, operation.bindings)
114-
}))
97+
const publisherChannels = this.mapChannel(k, v.description, v.publish, " producer")
98+
publisherChannels.forEach(channel => s.push(channel))
11599
});
116100
return s;
117101
}
118102

119-
private mapOperation(isSubscribe: boolean, message: Message, bindings?: any): Operation {
103+
private mapChannel(
104+
topicName: string,
105+
description: ServerAsyncApi["channels"][""]["description"],
106+
operation: ServerAsyncApi["channels"][""]["subscribe"] | ServerAsyncApi["channels"][""]["publish"],
107+
operationName: string): Channel[]
108+
{
109+
if(operation !== undefined) {
110+
let messages: Message[] = 'oneOf' in operation.message ? operation.message.oneOf : [operation.message];
111+
112+
return messages.map(message => {
113+
return {
114+
name: topicName,
115+
description: description,
116+
operation: this.mapOperation(operationName, message, operation.bindings)
117+
}
118+
})
119+
}
120+
return [];
121+
}
122+
123+
private mapOperation(operationName: string, message: Message, bindings?: any): Operation {
120124
return {
121-
type: this.getProtocol(bindings) + (isSubscribe ? " producer" : " consumer"),
125+
type: this.getProtocol(bindings) + operationName,
122126
message: message,
123127
bindings: bindings
124128
}

0 commit comments

Comments
 (0)