Skip to content
Open
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 @@ -56,7 +56,7 @@

String description() default "";

String value() default "";
String[] value() default "";

/**
* The schema type of the header value according to AsyncAPI specification.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private static Set<String> getHeadersType(List<AsyncOperation.Headers.Header> va
private static List<String> getHeaderValues(
List<AsyncOperation.Headers.Header> value, StringValueResolver stringValueResolver) {
return value.stream()
.map(AsyncOperation.Headers.Header::value)
.flatMap(it -> Arrays.stream(it.value()))
.filter(StringUtils::hasText)
.flatMap(text -> Optional.ofNullable(stringValueResolver.resolveStringValue(text)).stream())
.sorted()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void getAsyncHeaders(Class<?> classWithOperationBindingProcessor) throws Excepti
.as(headers.getProperties() + " does not contain key 'headerResolved'")
.isTrue();
SchemaObject headerResolved = (SchemaObject) headers.getProperties().get("headerResolved");
assertThat(headerResolved.getType()).containsExactly("string");
assertThat(headerResolved.getType()).containsExactly("integer");
assertThat(headerResolved.getExamples().get(0)).isEqualTo("valueResolved");
assertThat(headerResolved.getDescription()).isEqualTo("descriptionResolved");
assertThat(headerResolved.getFormat()).isEqualTo("int32Resolved");
Expand Down Expand Up @@ -101,6 +101,23 @@ void getAsyncHeadersWithoutSchemaName() throws Exception {
assertThat(headers.getTitle()).isNotNull();
}

@Test
void getAsyncHeadersWithMergedValue() throws Exception {
// given
Method m = ClassWithHeaders.class.getDeclaredMethod("withMergedValue", String.class);
AsyncOperation operation = m.getAnnotation(AsyncListener.class).operation();

// when
SchemaObject headers = AsyncAnnotationUtil.getAsyncHeaders(operation, stringValueResolver);

// then
SchemaObject headerProperty = (SchemaObject) headers.getProperties().get("headerResolved");
assertThat(headerProperty.getEnumValues())
.containsExactlyInAnyOrder("valueResolved", "value2Resolved", "value3Resolved");
assertThat(headerProperty.getExamples())
.containsExactlyInAnyOrder("valueResolved", "value2Resolved", "value3Resolved");
}

@Test
void getAsyncHeadersWithoutValue() throws Exception {
// given
Expand Down Expand Up @@ -131,7 +148,7 @@ void getAsyncHeadersWithFormat() throws Exception {
}

@Test
void getAsyncHeadersWithEmptyFormat() throws Exception {
void processAsyncHeadersWithEmptyFormat() throws Exception {
// given
Method m = ClassWithHeaders.class.getDeclaredMethod("withoutFormat", String.class);
AsyncOperation operation = m.getAnnotation(AsyncListener.class).operation();
Expand All @@ -145,7 +162,7 @@ void getAsyncHeadersWithEmptyFormat() throws Exception {
}

@Test
void getAsyncHeadersWithType() throws Exception {
void processAsyncHeadersWithType() throws Exception {
// given
Method m = ClassWithHeaders.class.getDeclaredMethod("withType", String.class);
AsyncOperation operation = m.getAnnotation(AsyncListener.class).operation();
Expand All @@ -159,7 +176,7 @@ void getAsyncHeadersWithType() throws Exception {
}

@Test
void getAsyncHeadersWithoutType() throws Exception {
void processAsyncHeadersWithoutType() throws Exception {
// given
Method m = ClassWithHeaders.class.getDeclaredMethod("withoutType", String.class);
AsyncOperation operation = m.getAnnotation(AsyncListener.class).operation();
Expand Down Expand Up @@ -303,7 +320,7 @@ void processMessageFromAnnotationWithAsyncMessage(Class<?> classWithOperationBin
}

@Test
void getServers() throws Exception {
void processServers() throws Exception {
Method m = ClassWithOperationBindingProcessor.class.getDeclaredMethod("methodWithAnnotation", String.class);
AsyncOperation operation = m.getAnnotation(AsyncListener.class).operation();

Expand Down Expand Up @@ -371,6 +388,7 @@ private static class ClassWithOperationBindingProcessor {
name = "header",
value = "value",
description = "description",
type = SchemaType.INTEGER,
format = "int32"),
@AsyncOperation.Headers.Header(
name = "headerWithoutValue",
Expand All @@ -384,15 +402,6 @@ private void methodWithAnnotation(String payload) {}
@AsyncOperation(
channelName = "${test.property.test-channel}",
description = "${test.property.description}",
headers =
@AsyncOperation.Headers(
schemaName = "TestSchema",
values = {
@AsyncOperation.Headers.Header(
name = "header",
value = "value",
description = "description")
}),
message =
@AsyncMessage(
description = "Message description",
Expand All @@ -419,6 +428,7 @@ private static class ClassWithAbstractOperationBindingProcessor {
name = "header",
value = "value",
description = "description",
type = SchemaType.INTEGER,
format = "int32"),
@AsyncOperation.Headers.Header(
name = "headerWithoutValue",
Expand All @@ -432,15 +442,6 @@ private void methodWithAnnotation(String payload) {}
@AsyncOperation(
channelName = "${test.property.test-channel}",
description = "${test.property.description}",
headers =
@AsyncOperation.Headers(
schemaName = "TestSchema",
values = {
@AsyncOperation.Headers.Header(
name = "header",
value = "value",
description = "description")
}),
message =
@AsyncMessage(
description = "Message description",
Expand All @@ -454,7 +455,6 @@ private void methodWithAsyncMessageAnnotation(String payload) {}

private static class ClassWithHeaders {
@AsyncListener(operation = @AsyncOperation(channelName = "${test.property.test-channel}"))
@TestOperationBindingProcessor.TestOperationBinding()
private void emptyHeaders(String payload) {}

@AsyncListener(
Expand All @@ -466,17 +466,32 @@ private void emptyHeaders(String payload) {}
values = {
@AsyncOperation.Headers.Header(name = "header", value = "value")
})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withoutSchemaName(String payload) {}

@AsyncListener(
operation =
@AsyncOperation(
channelName = "${test.property.test-channel}",
headers =
@AsyncOperation.Headers(
values = {
@AsyncOperation.Headers.Header(name = "header", value = "value"),
@AsyncOperation.Headers.Header(
name = "header",
value = {"value2", "value3"}),
@AsyncOperation.Headers.Header(
name = "unrelated-header",
value = "otherValue")
})))
private void withMergedValue(String payload) {}

@AsyncListener(
operation =
@AsyncOperation(
channelName = "${test.property.test-channel}",
headers =
@AsyncOperation.Headers(
values = {@AsyncOperation.Headers.Header(name = "header")})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withoutValue(String payload) {}

@AsyncListener(
Expand All @@ -488,7 +503,6 @@ private void withoutValue(String payload) {}
values = {
@AsyncOperation.Headers.Header(name = "header", format = "int32")
})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withFormat(String payload) {}

@AsyncListener(
Expand All @@ -498,7 +512,6 @@ private void withFormat(String payload) {}
headers =
@AsyncOperation.Headers(
values = {@AsyncOperation.Headers.Header(name = "header")})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withoutFormat(String payload) {}

@AsyncListener(
Expand All @@ -512,7 +525,6 @@ private void withoutFormat(String payload) {}
name = "header",
type = SchemaType.INTEGER)
})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withType(String payload) {}

@AsyncListener(
Expand All @@ -522,7 +534,6 @@ private void withType(String payload) {}
headers =
@AsyncOperation.Headers(
values = {@AsyncOperation.Headers.Header(name = "header")})))
@TestOperationBindingProcessor.TestOperationBinding()
private void withoutType(String payload) {}

@AsyncListener(
Expand All @@ -537,7 +548,6 @@ private void withoutType(String payload) {}
value = "value",
description = "non unique header")
})))
@TestOperationBindingProcessor.TestOperationBinding()
private void differentHeadersWithoutSchemaName(String payload) {}
}

Expand Down
1 change: 1 addition & 0 deletions springwolf-examples/springwolf-kafka-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ plugins {
}

dependencies {
implementation project(":springwolf-asyncapi")
implementation project(":springwolf-core")
implementation project(":springwolf-plugins:springwolf-kafka")
permitUnusedDeclared project(":springwolf-plugins:springwolf-kafka")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.examples.kafka.producers;

import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.bindings.kafka.annotations.KafkaAsyncOperationBinding;
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
import io.github.springwolf.core.asyncapi.annotations.AsyncPublisher;
Expand Down Expand Up @@ -32,6 +33,11 @@ public class AnotherProducer {
@AsyncOperation.Headers.Header(
name = "my_uuid_field",
description = "Event identifier",
value = {
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
},
type = SchemaType.STRING,
format = "uuid")
})))
@KafkaAsyncOperationBinding
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.examples.kafka.producers;

import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
import io.github.springwolf.bindings.kafka.annotations.KafkaAsyncOperationBinding;
import io.github.springwolf.core.asyncapi.annotations.AsyncOperation;
import io.github.springwolf.core.asyncapi.annotations.AsyncPublisher;
Expand Down Expand Up @@ -57,7 +58,9 @@ public class NestedProducer {
@AsyncOperation.Headers.Header(
name = AsyncHeadersCloudEventConstants.TIME,
description = AsyncHeadersCloudEventConstants.TIME_DESC,
value = "2023-10-28 20:01:23+00:00"),
value = "2023-10-28T20:01:23+00:00",
type = SchemaType.STRING,
format = "date-time"),
@AsyncOperation.Headers.Header(
name = AsyncHeadersCloudEventConstants.TYPE,
description = AsyncHeadersCloudEventConstants.TYPE_DESC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,12 @@
"title": "ce_time",
"type": "string",
"description": "CloudEvent Time Header",
"format": "date-time",
"enum": [
"2023-10-28 20:01:23+00:00"
"2023-10-28T20:01:23+00:00"
],
"examples": [
"2023-10-28 20:01:23+00:00"
"2023-10-28T20:01:23+00:00"
]
},
"ce_type": {
Expand Down Expand Up @@ -364,7 +365,7 @@
"ce_source": "http://localhost",
"ce_specversion": "1.0",
"ce_subject": "Springwolf example project - Kafka",
"ce_time": "2023-10-28 20:01:23+00:00",
"ce_time": "2023-10-28T20:01:23+00:00",
"ce_type": "NestedPayloadDto.v1",
"content-type": "application/json"
}
Expand Down Expand Up @@ -416,8 +417,9 @@
"ce_time": {
"description": "CloudEvent Time Header",
"enum": [
"2023-10-28 20:01:23+00:00"
"2023-10-28T20:01:23+00:00"
],
"format": "date-time",
"title": "ce_time",
"type": "string"
},
Expand Down Expand Up @@ -529,13 +531,21 @@
"title": "my_uuid_field",
"type": "string",
"description": "Event identifier",
"format": "uuid"
"format": "uuid",
"enum": [
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
],
"examples": [
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
]
}
},
"examples": [
{
"__TypeId__": "string",
"my_uuid_field": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
"my_uuid_field": "00000000-0000-0000-0000-000000000000"
}
],
"x-json-schema": {
Expand All @@ -548,6 +558,10 @@
},
"my_uuid_field": {
"description": "Event identifier",
"enum": [
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
],
"format": "uuid",
"title": "my_uuid_field",
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
"ce_source": "http://localhost",
"ce_specversion": "1.0",
"ce_subject": "Springwolf example project - Kafka",
"ce_time": "2023-10-28 20:01:23+00:00",
"ce_time": "2023-10-28T20:01:23+00:00",
"ce_type": "NestedPayloadDto.v1",
"content-type": "application/json"
},
Expand Down Expand Up @@ -321,12 +321,13 @@
},
"ce_time": {
"type": "string",
"format": "date-time",
"description": "CloudEvent Time Header",
"enum": [
"2023-10-28 20:01:23+00:00"
"2023-10-28T20:01:23+00:00"
],
"examples": [
"2023-10-28 20:01:23+00:00"
"2023-10-28T20:01:23+00:00"
],
"title": "ce_time"
},
Expand Down Expand Up @@ -408,7 +409,7 @@
"type": "object",
"example": {
"__TypeId__": "string",
"my_uuid_field": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
"my_uuid_field": "00000000-0000-0000-0000-000000000000"
},
"properties": {
"__TypeId__": {
Expand All @@ -420,6 +421,14 @@
"type": "string",
"format": "uuid",
"description": "Event identifier",
"enum": [
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
],
"examples": [
"00000000-0000-0000-0000-000000000000",
"FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
],
"title": "my_uuid_field"
}
},
Expand Down
Loading
Loading