Skip to content

Commit

Permalink
chore(kafka-example): add example for schema with with examples in ya…
Browse files Browse the repository at this point in the history
…ml format
  • Loading branch information
sam0r040 committed Feb 23, 2024
1 parent bb8623d commit 91043a5
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.kafka.consumers;

import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncListener;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncMessage;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.AsyncOperation;
import io.github.stavshamir.springwolf.asyncapi.scanners.channels.operationdata.annotation.KafkaAsyncOperationBinding;
import io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
@Slf4j
public class YamlConsumer {

@AsyncListener(
operation =
@AsyncOperation(
channelName = "yaml-topic",
description = "Showcases a xml based message",
message = @AsyncMessage(contentType = "application/yaml")))
@KafkaAsyncOperationBinding
@KafkaListener(topics = "yaml-topic")
public void receiveExamplePayload(YamlPayloadDto payload) {
log.info("Received new message in example-queue: {}", payload.toString());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.stavshamir.springwolf.example.kafka.dtos;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class YamlPayloadDto {

private String someString;

private long someLong;

private ExampleEnum someEnum;

public enum ExampleEnum {
FOO1,
FOO2,
FOO3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void asyncApiResourceArtifactTest() throws IOException {
Files.writeString(Path.of("src", "test", "resources", "asyncapi.actual.json"), actualPatched);

InputStream s = this.getClass().getResourceAsStream("/asyncapi.json");
String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8);
String expected = new String(s.readAllBytes(), StandardCharsets.UTF_8).trim();

assertEquals(expected, actualPatched);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void testContextWithApplicationProperties() {

@Test
void testAllChannelsAreFound() {
assertThat(asyncApiService.getAsyncAPI().getChannels()).hasSize(8);
assertThat(asyncApiService.getAsyncAPI().getChannels()).hasSize(9);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@
"$ref": "#/components/messages/io.github.stavshamir.springwolf.example.kafka.dtos.XmlPayloadDto"
}
}
},
"yaml-topic": {
"messages": {
"io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto": {
"$ref": "#/components/messages/io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto"
}
}
}
},
"components": {
Expand Down Expand Up @@ -837,6 +844,50 @@
},
"type": "object"
}
},
"io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto": {
"type": "object",
"properties": {
"someEnum": {
"type": "string",
"enum": [
"FOO1",
"FOO2",
"FOO3"
]
},
"someLong": {
"type": "integer",
"format": "int64"
},
"someString": {
"type": "string"
}
},
"examples": [
"someEnum: FOO1\nsomeLong: 0\nsomeString: string\n"
],
"x-json-schema": {
"$schema": "https://json-schema.org/draft-04/schema#",
"properties": {
"someEnum": {
"enum": [
"FOO1",
"FOO2",
"FOO3"
],
"type": "string"
},
"someLong": {
"format": "int64",
"type": "integer"
},
"someString": {
"type": "string"
}
},
"type": "object"
}
}
},
"messages": {
Expand Down Expand Up @@ -975,6 +1026,25 @@
}
}
},
"io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto": {
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
},
"payload": {
"schemaFormat": "application/vnd.aai.asyncapi+json;version=3.0.0",
"schema": {
"$ref": "#/components/schemas/io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto"
}
},
"contentType": "application/yaml",
"name": "io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto",
"title": "YamlPayloadDto",
"bindings": {
"kafka": {
"bindingVersion": "0.4.0"
}
}
},
"java.lang.String": {
"headers": {
"$ref": "#/components/schemas/HeadersNotDocumented"
Expand Down Expand Up @@ -1207,6 +1277,24 @@
"$ref": "#/channels/xml-topic/messages/io.github.stavshamir.springwolf.example.kafka.dtos.XmlPayloadDto"
}
]
},
"yaml-topic_receive_receiveExamplePayload": {
"action": "receive",
"channel": {
"$ref": "#/channels/yaml-topic"
},
"title": "yaml-topic_receive",
"description": "Showcases a xml based message",
"bindings": {
"kafka": {
"bindingVersion": "0.4.0"
}
},
"messages": [
{
"$ref": "#/channels/yaml-topic/messages/io.github.stavshamir.springwolf.example.kafka.dtos.YamlPayloadDto"
}
]
}
}
}
}

0 comments on commit 91043a5

Please sign in to comment.