From 6f69894bfd6dd4adf77c1d78711aee8778fc6966 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Sun, 19 May 2024 17:31:32 +0200 Subject: [PATCH 1/4] feat(ui): show operation and message description --- .../channel-main/channel-main.component.css | 14 ++++++++++++++ .../channel-main/channel-main.component.html | 15 +++++++++++---- springwolf-ui/src/app/models/message.model.ts | 1 + springwolf-ui/src/app/models/operation.model.ts | 1 + .../service/asyncapi/asyncapi-mapper.service.ts | 13 +++++++++---- .../service/asyncapi/models/operations.model.ts | 1 + 6 files changed, 37 insertions(+), 8 deletions(-) diff --git a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.css b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.css index 545231e1c..723f3a9a3 100644 --- a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.css +++ b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.css @@ -33,6 +33,20 @@ button { height: 50px; } +.table { + display: table; +} +.table .table-row { + display: table-row; +} +.table-row * { + display: table-cell; +} +.table-row *:first-child { + font-weight: bold; + padding-right: 8px; +} + [hidden] { display: none !important; } diff --git a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.html b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.html index dc2ddcd03..2a8d66041 100644 --- a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.html +++ b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.html @@ -1,10 +1,17 @@
-
-

- -

+
+
+
+ Operation description + +
+
+ Message description + +
+
diff --git a/springwolf-ui/src/app/models/message.model.ts b/springwolf-ui/src/app/models/message.model.ts index b12c9d8a7..531d01201 100644 --- a/springwolf-ui/src/app/models/message.model.ts +++ b/springwolf-ui/src/app/models/message.model.ts @@ -7,6 +7,7 @@ export interface Message { description?: string; payload: { name: string; + type: string; title: string; anchorUrl: string; }; diff --git a/springwolf-ui/src/app/models/operation.model.ts b/springwolf-ui/src/app/models/operation.model.ts index a15907543..76f31400b 100644 --- a/springwolf-ui/src/app/models/operation.model.ts +++ b/springwolf-ui/src/app/models/operation.model.ts @@ -4,6 +4,7 @@ import { Bindings } from "./bindings.model"; export type OperationType = "receive" | "send"; export interface Operation { + description?: string; message: Message; bindings?: Bindings; protocol?: string; diff --git a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts index 9aa70b1fd..5d8526a30 100644 --- a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts @@ -108,7 +108,8 @@ export class AsyncApiMapperService { channels[channelName], message, operation.action, - operation.bindings + operation.bindings, + operation.description ) ); @@ -126,12 +127,14 @@ export class AsyncApiMapperService { channel: ServerChannel, message: Message, operationType: ServerOperation["action"], - operationBinding: ServerBindings + operationBinding: ServerBindings, + description?: string ): ChannelOperation { const operation = this.mapOperation( operationType, message, - operationBinding + operationBinding, + description ); return { @@ -230,11 +233,13 @@ export class AsyncApiMapperService { private mapOperation( operationType: ServerOperation["action"], message: Message, - bindings?: Bindings + bindings?: Bindings, + description?: string ): Operation { return { protocol: this.getProtocol(bindings), operationType: operationType == "send" ? "send" : "receive", + description, message, bindings, }; diff --git a/springwolf-ui/src/app/service/asyncapi/models/operations.model.ts b/springwolf-ui/src/app/service/asyncapi/models/operations.model.ts index e498af5da..3fd1b32c3 100644 --- a/springwolf-ui/src/app/service/asyncapi/models/operations.model.ts +++ b/springwolf-ui/src/app/service/asyncapi/models/operations.model.ts @@ -7,6 +7,7 @@ export interface ServerOperations { export interface ServerOperation { action: string; + description?: string; channel: { $ref: string; }; From 95da0ce7e89da4d2ef610ce5f04a3b5ed3e91b87 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Sun, 19 May 2024 17:41:29 +0200 Subject: [PATCH 2/4] fix(ui): fix publishing for custom payloadType For example in combination with `@AsyncMessage#name` --- .../examples/kafka/consumers/StringConsumer.java | 2 ++ .../src/test/resources/asyncapi.json | 10 +++++----- .../channels/channel-main/channel-main.component.ts | 2 +- .../app/service/asyncapi/asyncapi-mapper.service.ts | 1 + 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/springwolf/examples/kafka/consumers/StringConsumer.java b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/springwolf/examples/kafka/consumers/StringConsumer.java index 117d3fc4a..72598d3ac 100644 --- a/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/springwolf/examples/kafka/consumers/StringConsumer.java +++ b/springwolf-examples/springwolf-kafka-example/src/main/java/io/github/springwolf/examples/kafka/consumers/StringConsumer.java @@ -3,6 +3,7 @@ import io.github.springwolf.core.asyncapi.annotations.AsyncApiPayload; import io.github.springwolf.core.asyncapi.annotations.AsyncListener; +import io.github.springwolf.core.asyncapi.annotations.AsyncMessage; import io.github.springwolf.core.asyncapi.annotations.AsyncOperation; import io.github.springwolf.plugins.kafka.asyncapi.annotations.KafkaAsyncOperationBinding; import io.swagger.v3.oas.annotations.media.Schema; @@ -28,6 +29,7 @@ public class StringConsumer { description = "Final classes (like String) can be documented using an envelope class and the @AsyncApiPayload annotation.", payloadType = StringEnvelope.class, + message = @AsyncMessage(name = "StringPayload"), headers = @AsyncOperation.Headers(notUsed = true))) @KafkaAsyncOperationBinding public void receiveStringPayload(String stringPayload) { diff --git a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json index 7e3c5f037..d08fdf013 100644 --- a/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json +++ b/springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json @@ -104,8 +104,8 @@ }, "string-topic": { "messages": { - "io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope": { - "$ref": "#/components/messages/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" + "StringPayload": { + "$ref": "#/components/messages/StringPayload" }, "java.lang.String": { "$ref": "#/components/messages/java.lang.String" @@ -1213,7 +1213,7 @@ } } }, - "io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope": { + "StringPayload": { "headers": { "$ref": "#/components/schemas/HeadersNotUsed" }, @@ -1223,7 +1223,7 @@ "$ref": "#/components/schemas/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" } }, - "name": "io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope", + "name": "StringPayload", "title": "StringEnvelope", "description": "Payload description using @Schema annotation and @AsyncApiPayload within envelope class", "bindings": { @@ -1604,7 +1604,7 @@ }, "messages": [ { - "$ref": "#/channels/string-topic/messages/io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope" + "$ref": "#/channels/string-topic/messages/StringPayload" }, { "$ref": "#/channels/string-topic/messages/java.lang.String" diff --git a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts index bf4f2c535..23aa8f964 100644 --- a/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts +++ b/springwolf-ui/src/app/components/channels/channel-main/channel-main.component.ts @@ -47,7 +47,7 @@ export class ChannelMainComponent implements OnInit { this.defaultExample = this.schema.example; this.exampleTextAreaLineCount = this.defaultExample?.lineCount || 1; - this.defaultExampleType = this.operation.message.name; + this.defaultExampleType = this.operation.message.payload.type; this.headersSchemaIdentifier = this.operation.message.headers.name.slice( this.operation.message.headers.name.lastIndexOf("/") + 1 diff --git a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts index 5d8526a30..b2ae2687a 100644 --- a/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts +++ b/springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts @@ -178,6 +178,7 @@ export class AsyncApiMapperService { payload: { name: message.payload.schema.$ref, title: this.resolveRef(message.payload.schema.$ref), + type: this.resolveRef(message.payload.schema.$ref), anchorUrl: AsyncApiMapperService.BASE_URL + this.resolveRef(message.payload.schema.$ref), From 50f771b1b860ac4707ef38f761ae236ed57a0d91 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Sun, 19 May 2024 17:41:49 +0200 Subject: [PATCH 3/4] cleanup(ui): simplify mock-server.ts --- springwolf-ui/src/app/service/mock/mock-server.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/springwolf-ui/src/app/service/mock/mock-server.ts b/springwolf-ui/src/app/service/mock/mock-server.ts index 94c10f15d..17baf2eaa 100644 --- a/springwolf-ui/src/app/service/mock/mock-server.ts +++ b/springwolf-ui/src/app/service/mock/mock-server.ts @@ -8,7 +8,7 @@ import { exampleSchemas } from "./example-data"; export class MockServer implements InMemoryDbService { createDb() { - return { kafka: [] }; + return {}; } get(reqInfo: RequestInfo) { From e65af39199e6ee1df5bee8f5bcc7577890aef495 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Sun, 19 May 2024 18:41:47 +0200 Subject: [PATCH 4/4] test(e2e): Update payloadType assertion --- .../e2e/tests/publishing.spec.ts | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/springwolf-examples/e2e/tests/publishing.spec.ts b/springwolf-examples/e2e/tests/publishing.spec.ts index 373b403d3..bc6230aa4 100644 --- a/springwolf-examples/e2e/tests/publishing.spec.ts +++ b/springwolf-examples/e2e/tests/publishing.spec.ts @@ -61,6 +61,11 @@ function testPublishingEveryChannelItem() { const channelName = operation.channel.$ref.split("/").pop(); const schemaType = messageReference.$ref.split("/").pop(); const payload = asyncApiDoc.components.messages[schemaType]?.title; + const payloadType = asyncApiDoc.components.messages[ + schemaType + ]?.payload.schema.$ref + .split("/") + .pop(); if ( payload === "AnotherPayloadAvroDto" || // Avro publishing is not supported @@ -100,13 +105,15 @@ function testPublishingEveryChannelItem() { const found = dockerLogs.messages .filter((m) => m.includes("Publishing to")) .filter((m) => m.includes(channelName)) - .filter((m) => m.includes(schemaType)).length; + .filter((m) => m.includes(payloadType)).length; console.debug( - "Polling for publish message and found=" + found + `Polling for publish message and found=${found}` ); return found; }, - { message: "Expected publishing message in application logs" } + { + message: `Expected publishing message in application logs in channel ${channelName} with type ${payloadType}`, + } ) .toBeGreaterThanOrEqual(1); } @@ -118,12 +125,12 @@ function testPublishingEveryChannelItem() { .filter((m) => m.includes("Received new message in")) .filter((m) => m.includes(channelName)).length; console.debug( - "Polling for receive message and found=" + found + `Polling for receive message and found=${found}` ); return found; }, { - message: "Expected receiving message in appliation logs", + message: `Expected receiving message in application logs in channel ${channelName}`, timeout: 10_000, } )