Skip to content

feat(ui): Show operation and message description, fix publishing when using AsyncMessage#name #762

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

Merged
merged 4 commits into from
May 24, 2024
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
17 changes: 12 additions & 5 deletions springwolf-examples/e2e/tests/publishing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand All @@ -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,
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1213,7 +1213,7 @@
}
}
},
"io.github.springwolf.examples.kafka.consumers.StringConsumer$StringEnvelope": {
"StringPayload": {
"headers": {
"$ref": "#/components/schemas/HeadersNotUsed"
},
Expand All @@ -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": {
Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
<!-- SPDX-License-Identifier: Apache-2.0 -->
<section>
<mat-divider></mat-divider>
<div *ngIf="operation.message.description">
<p>
<markdown [data]="operation.message.description"></markdown>
</p>
<div *ngIf="operation.description || operation.message.description">
<div class="table">
<div *ngIf="operation.description" class="table-row">
<span>Operation description</span>
<markdown [data]="operation.description"></markdown>
</div>
<div *ngIf="operation.message.description" class="table-row">
<span>Message description</span>
<markdown [data]="operation.message.description"></markdown>
</div>
</div>
<mat-divider></mat-divider>
</div>
<mat-tab-group animationDuration="0ms">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/models/message.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface Message {
description?: string;
payload: {
name: string;
type: string;
title: string;
anchorUrl: string;
};
Expand Down
1 change: 1 addition & 0 deletions springwolf-ui/src/app/models/operation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 10 additions & 4 deletions springwolf-ui/src/app/service/asyncapi/asyncapi-mapper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export class AsyncApiMapperService {
channels[channelName],
message,
operation.action,
operation.bindings
operation.bindings,
operation.description
)
);

Expand All @@ -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 {
Expand Down Expand Up @@ -175,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),
Expand Down Expand Up @@ -230,11 +234,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,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface ServerOperations {

export interface ServerOperation {
action: string;
description?: string;
channel: {
$ref: string;
};
Expand Down
2 changes: 1 addition & 1 deletion springwolf-ui/src/app/service/mock/mock-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { exampleSchemas } from "./example-data";

export class MockServer implements InMemoryDbService {
createDb() {
return { kafka: [] };
return {};
}

get(reqInfo: RequestInfo) {
Expand Down