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: Added support for Message description #211

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.PayloadReference;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference;
import io.github.stavshamir.springwolf.schemas.SchemasService;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;

Expand Down Expand Up @@ -94,10 +95,13 @@ private Message buildMessage(OperationData operationData) {
String modelName = this.getSchemaService().register(payloadType);
String headerModelName = this.getSchemaService().register(operationData.getHeaders());

Schema schema = payloadType.getAnnotation(io.swagger.v3.oas.annotations.media.Schema.class);
String description = schema != null ? schema.description() : null;

return Message.builder()
.name(payloadType.getName())
.title(modelName)
// FIXME: Add support for Message Description
.description(description)
.payload(PayloadReference.fromModelName(modelName))
.headers(HeaderReference.fromModelName(headerModelName))
.bindings(operationData.getMessageBinding())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ void getAsyncAPI_producers_should_be_correct() {
final ChannelItem channel = actualChannels.get("producer-topic");
assertThat(channel.getSubscribe()).isNotNull();
final Message message = (Message) channel.getSubscribe().getMessage();
// Message description is not supported yet
assertThat(message.getDescription()).isNull();
assertThat(message.getBindings()).isEqualTo(ImmutableMap.of("kafka", new KafkaMessageBinding()));
}
Expand All @@ -125,7 +124,6 @@ void getAsyncAPI_consumers_should_be_correct() {
final ChannelItem channel = actualChannels.get("consumer-topic");
assertThat(channel.getPublish()).isNotNull();
final Message message = (Message) channel.getPublish().getMessage();
// Message description is not supported yet
assertThat(message.getDescription()).isNull();
assertThat(message.getBindings()).isEqualTo(ImmutableMap.of("kafka", new KafkaMessageBinding()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.schemas.DefaultSchemasService;
import io.swagger.v3.oas.annotations.media.Schema;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -65,14 +66,14 @@ void allFieldsConsumerData() {
assertThat(consumerChannels)
.containsKey(channelName);

String messageDescription = "Example Payload DTO Description";
Operation operation = Operation.builder()
.description(description)
.operationId("example-consumer-topic-foo1_publish")
.bindings(ImmutableMap.of("kafka", new KafkaOperationBinding()))
.message(Message.builder()
.name(ExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description)
.description(messageDescription)
.title(ExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName()))
Expand Down Expand Up @@ -142,20 +143,20 @@ void multipleConsumersForSameTopic() {
.hasSize(1)
.containsKey(channelName);

String messageDescription1 = "Example Payload DTO Description";
String messageDescription2 = "Another Example Payload DTO Description";
Set<Message> messages = ImmutableSet.of(
Message.builder()
.name(ExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description1)
.description(messageDescription1)
.title(ExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName()))
.bindings(ImmutableMap.of("kafka", new KafkaMessageBinding()))
.build(),
Message.builder()
.name(AnotherExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description2)
.description(messageDescription2)
.title(AnotherExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(AnotherExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_USED.getSchemaName()))
Expand Down Expand Up @@ -190,10 +191,12 @@ private void mockConsumers(Collection<ConsumerData> consumers) {
when(asyncApiDocketService.getAsyncApiDocket()).thenReturn(asyncApiDocket);
}

@Schema(description = "Example Payload DTO Description")
static class ExamplePayloadDto {
private String foo;
}

@Schema(description = "Another Example Payload DTO Description")
static class AnotherExamplePayloadDto {
private String bar;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.github.stavshamir.springwolf.configuration.AsyncApiDocket;
import io.github.stavshamir.springwolf.configuration.AsyncApiDocketService;
import io.github.stavshamir.springwolf.schemas.DefaultSchemasService;
import io.swagger.v3.oas.annotations.media.Schema;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -65,14 +66,14 @@ void allFieldsProducerData() {
assertThat(producerChannels)
.containsKey(channelName);

String messageDescription1 = "Example Payload DTO Description";
Operation operation = Operation.builder()
.description(description)
.operationId("example-producer-topic-foo1_subscribe")
.bindings(ImmutableMap.of("kafka", new KafkaOperationBinding()))
.message(Message.builder()
.name(ExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description)
.description(messageDescription1)
.title(ExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName()))
Expand Down Expand Up @@ -142,20 +143,20 @@ void multipleProducersForSameTopic() {
.hasSize(1)
.containsKey(channelName);

String messageDescription1 = "Example Payload DTO Description";
String messageDescription2 = "Another Example Payload DTO Description";
Set<Message> messages = ImmutableSet.of(
Message.builder()
.name(ExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description1)
.description(messageDescription1)
.title(ExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(ExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName()))
.bindings(ImmutableMap.of("kafka", new KafkaMessageBinding()))
.build(),
Message.builder()
.name(AnotherExamplePayloadDto.class.getName())
// Message description is not supported yet
// .description(description2)
.description(messageDescription2)
.title(AnotherExamplePayloadDto.class.getSimpleName())
.payload(PayloadReference.fromModelName(AnotherExamplePayloadDto.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_USED.getSchemaName()))
Expand Down Expand Up @@ -189,12 +190,13 @@ private void mockProducers(Collection<ProducerData> producers) {
when(asyncApiDocketService.getAsyncApiDocket()).thenReturn(asyncApiDocket);
}

@Schema(description = "Example Payload DTO Description")
static class ExamplePayloadDto {
private String foo;
}

@Schema(description = "Another Example Payload DTO Description")
static class AnotherExamplePayloadDto {
private String bar;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.AsyncHeaders;
import io.github.stavshamir.springwolf.asyncapi.types.channel.operation.message.header.HeaderReference;
import io.github.stavshamir.springwolf.schemas.DefaultSchemasService;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -66,8 +67,7 @@ void scan_componentHasListenerMethod() {
Message message = Message.builder()
.name(SimpleFoo.class.getName())
.title(SimpleFoo.class.getSimpleName())
// Message description is not supported yet
// .description("test channel operation description")
.description("SimpleFoo Message Description")
.payload(PayloadReference.fromModelName(SimpleFoo.class.getSimpleName()))
.headers(HeaderReference.fromModelName(AsyncHeaders.NOT_DOCUMENTED.getSchemaName()))
.bindings(EMPTY_MAP)
Expand Down Expand Up @@ -101,8 +101,7 @@ void scan_componentHasListenerMethodWithAllAttributes() {
Message message = Message.builder()
.name(SimpleFoo.class.getName())
.title(SimpleFoo.class.getSimpleName())
// Message description is not supported yet
// .description("description")
.description("SimpleFoo Message Description")
.payload(PayloadReference.fromModelName(SimpleFoo.class.getSimpleName()))
.headers(HeaderReference.fromModelName("TestSchema"))
.bindings(EMPTY_MAP)
Expand Down Expand Up @@ -144,8 +143,7 @@ void scan_componentHasMultipleListenerAnnotations() {
.description("test-channel-1-description")
.operationId("test-channel-1_publish")
.bindings(EMPTY_MAP)
// Message description is not supported yet
.message(builder/*.description("test-channel-1-description")*/.build())
.message(builder.description("SimpleFoo Message Description").build())
.build();

ChannelItem expectedChannel1 = ChannelItem.builder()
Expand All @@ -157,8 +155,7 @@ void scan_componentHasMultipleListenerAnnotations() {
.description("test-channel-2-description")
.operationId("test-channel-2_publish")
.bindings(EMPTY_MAP)
// Message description is not supported yet
.message(builder/*.description("test-channel-2-description")*/.build())
.message(builder.description("SimpleFoo Message Description").build())
.build();

ChannelItem expectedChannel2 = ChannelItem.builder()
Expand Down Expand Up @@ -228,6 +225,7 @@ private void methodWithMultipleAnnotation(SimpleFoo payload) {

@Data
@NoArgsConstructor
@Schema(description = "SimpleFoo Message Description")
private static class SimpleFoo {
private String s;
private boolean b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto",
"title" : "AnotherPayloadDto",
"description" : "Another payload model",
"payload" : {
"$ref" : "#/components/schemas/AnotherPayloadDto"
},
Expand Down Expand Up @@ -149,6 +150,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.amqp.dtos.AnotherPayloadDto",
"title" : "AnotherPayloadDto",
"description" : "Another payload model",
"payload" : {
"$ref" : "#/components/schemas/AnotherPayloadDto"
},
Expand Down Expand Up @@ -193,6 +195,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.amqp.dtos.ExamplePayloadDto",
"title" : "ExamplePayloadDto",
"description" : "Example payload model",
"payload" : {
"$ref" : "#/components/schemas/ExamplePayloadDto"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.kafka.dtos.ExamplePayloadDto",
"title" : "ExamplePayloadDto",
"description" : "Example payload model",
"payload" : {
"$ref" : "#/components/schemas/ExamplePayloadDto"
},
Expand Down Expand Up @@ -102,6 +103,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.kafka.dtos.AnotherPayloadDto",
"title" : "AnotherPayloadDto",
"description" : "Another payload model",
"payload" : {
"$ref" : "#/components/schemas/AnotherPayloadDto"
},
Expand Down Expand Up @@ -242,6 +244,7 @@
"schemaFormat" : "application/vnd.oai.openapi+json;version=3.0.0",
"name" : "io.github.stavshamir.springwolf.example.kafka.dtos.NestedPayloadDto",
"title" : "NestedPayloadDto",
"description" : "Payload model with nested complex types",
"payload" : {
"$ref" : "#/components/schemas/NestedPayloadDto"
},
Expand Down