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

Commit 012b024

Browse files
committed
Add support for channels with oneOf messages
1 parent b303d02 commit 012b024

File tree

6 files changed

+60
-38
lines changed

6 files changed

+60
-38
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
}
77

88
group = 'io.github.springwolf'
9-
version = '0.3.1' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
9+
version = '0.4.0' + (Boolean.valueOf(System.getProperty('snapshot')) ? '-SNAPSHOT' : '')
1010
sourceCompatibility = '1.8'
1111

1212
node {

src/app/channels/channel-main/channel-main.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class ChannelMainComponent implements OnInit {
1818
@Input() docName: string;
1919
@Input() channelName: string;
2020
@Input() operation: Operation;
21-
21+
2222
schema: Schema;
2323
defaultExample: Example;
2424
exampleTextAreaLineCount: number;
@@ -34,7 +34,7 @@ export class ChannelMainComponent implements OnInit {
3434

3535
ngOnInit(): void {
3636
this.asyncApiService.getAsyncApis().subscribe(
37-
asyncapi => {
37+
asyncapi => {
3838
let schemas: Map<string, Schema> = asyncapi.get(this.docName).components.schemas;
3939
this.schema = schemas.get(this.operation.message.title);
4040
this.defaultExample = this.schema.example;

src/app/channels/channels.component.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,11 @@
99
mat-divider {
1010
height: 20px;
1111
}
12+
13+
.payload-name {
14+
background-color: #E0E0E0;
15+
border-radius: 4px;
16+
padding: 4px;
17+
font-weight: normal;
18+
font-size: small;
19+
}

src/app/channels/channels.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ <h1>Channels</h1>
55
<mat-panel-title fxLayout fxLayoutAlign="flex-start center" fxLayoutGap="16px">
66
<div class="operation-badge">{{ channel.operation.type }}</div>
77
<h3>{{ channel.name }}</h3>
8+
<div class="payload-name">{{ channel.operation.message.title }}</div>
89
</mat-panel-title>
910
</mat-expansion-panel-header>
1011
<app-channel-main

src/app/shared/asyncapi.service.ts

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,36 @@ export class AsyncApiService {
103103
bindings?: any;
104104
};
105105
publish?: {
106-
message: Message;
106+
message: Message | { oneOf: Message[] };
107107
bindings?: any;
108108
};
109109
}
110110
}): Channel[] {
111111
const s = new Array<Channel>();
112-
Object.entries(channels).forEach(([k, v]) => s.push({
113-
name: k,
114-
description: v.description,
115-
operation: this.mapOperation(v.subscribe, v.publish)
116-
}));
112+
Object.entries(channels).forEach(([k, v]) => {
113+
let operation = v.publish ? v.publish : v.subscribe;
114+
let isSubscribe = !!v.subscribe;
115+
116+
let messages: Message[] = 'oneOf' in operation.message ? operation.message.oneOf : [operation.message];
117+
messages.forEach(message => s.push({
118+
name: k,
119+
description: v.description,
120+
operation: this.mapOperation(isSubscribe, message, operation.bindings)
121+
}))
122+
});
117123
return s;
118124
}
119125

120-
private mapOperation(subscribe: { message: Message; bindings?: any; }, publish: { message: Message; bindings?: any; }): Operation {
121-
const isSubscribe = !!subscribe;
122-
123-
if (isSubscribe) {
124-
return {
125-
type: this.getProtocol(subscribe) + " producer",
126-
message: subscribe.message,
127-
bindings: subscribe.bindings
128-
}
129-
} else {
130-
return {
131-
type: this.getProtocol(publish) + " consumer",
132-
message: publish.message,
133-
bindings: publish.bindings
134-
}
126+
private mapOperation(isSubscribe: boolean, message: Message, bindings?: any): Operation {
127+
return {
128+
type: this.getProtocol(bindings) + (isSubscribe ? " producer" : " consumer"),
129+
message: message,
130+
bindings: bindings
135131
}
136132
}
137133

138-
private getProtocol(operation: { message: Message; bindings?: any; }): string {
139-
return Object.keys(operation.bindings)[0];
134+
private getProtocol(bindings?: any): string {
135+
return Object.keys(bindings)[0];
140136
}
141137

142138
mapSchemas(schemas: { [key: string]: { type: string; properties: object; example: object; } }): Map<string, Schema> {

src/app/shared/mock.json

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
}
1414
},
1515
"channels": {
16-
"another-topic": {
17-
"subscribe": {
16+
"example-consumer-topic": {
17+
"publish": {
1818
"bindings": {
1919
"kafka": {
2020
"groupId": {
@@ -34,17 +34,10 @@
3434
}
3535
}
3636
},
37-
"example-topic": {
37+
"example-producer-topic": {
3838
"subscribe": {
3939
"bindings": {
40-
"kafka": {
41-
"groupId": {
42-
"type": "string",
43-
"enum": [
44-
""
45-
]
46-
}
47-
}
40+
"kafka": {}
4841
},
4942
"message": {
5043
"name": "io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto",
@@ -54,6 +47,31 @@
5447
}
5548
}
5649
}
50+
},
51+
"multi-payload-topic": {
52+
"publish": {
53+
"bindings": {
54+
"kafka": {}
55+
},
56+
"message": {
57+
"oneOf": [
58+
{
59+
"name": "io.github.stavshamir.springwolf.example.dtos.ExamplePayloadDto",
60+
"title": "ExamplePayloadDto",
61+
"payload": {
62+
"$ref": "#/components/schemas/ExamplePayloadDto"
63+
}
64+
},
65+
{
66+
"name": "io.github.stavshamir.springwolf.example.dtos.AnotherPayloadDto",
67+
"title": "AnotherPayloadDto",
68+
"payload": {
69+
"$ref": "#/components/schemas/AnotherPayloadDto"
70+
}
71+
}
72+
]
73+
}
74+
}
5775
}
5876
},
5977
"components": {
@@ -157,7 +175,6 @@
157175
"type": "string",
158176
"enum": [
159177
"FOO1"
160-
161178
]
162179
}
163180
},

0 commit comments

Comments
 (0)