From 36f14dd4b14c6c8ed4da2b7f97d185a01b5e0c21 Mon Sep 17 00:00:00 2001 From: Timon Back Date: Wed, 16 Sep 2026 15:27:02 +0200 Subject: [PATCH] feat: handle empty header value --- .../asyncapi/annotations/AsyncOperation.java | 2 +- .../annotation/AsyncAnnotationUtil.java | 1 - .../annotation/AsyncAnnotationUtilTest.java | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/annotations/AsyncOperation.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/annotations/AsyncOperation.java index 0f6583174..77230d6a2 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/annotations/AsyncOperation.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/annotations/AsyncOperation.java @@ -62,7 +62,7 @@ String description() default ""; - String[] value() default ""; + String[] value() default {}; /** * The schema type of the header value according to AsyncAPI specification. diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java index 4c09eb8f0..eec7aea8d 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtil.java @@ -98,7 +98,6 @@ private static List getHeaderValues( List value, StringValueResolver stringValueResolver) { return value.stream() .flatMap(it -> Arrays.stream(it.value())) - .filter(StringUtils::hasText) .flatMap(text -> Optional.ofNullable(stringValueResolver.resolveStringValue(text)).stream()) .sorted() .toList(); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtilTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtilTest.java index 407ddc81f..59dee6947 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtilTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/common/annotation/AsyncAnnotationUtilTest.java @@ -133,6 +133,21 @@ void getAsyncHeadersWithoutValue() throws Exception { assertThat(headerProperty.getExamples()).isNull(); } + @Test + void getAsyncHeadersWithEmptyValue() throws Exception { + // given + Method m = ClassWithHeaders.class.getDeclaredMethod("withEmptyValue", 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()).containsExactly("Resolved"); + assertThat(headerProperty.getExamples()).containsExactly("Resolved"); + } + @Test void getAsyncHeadersWithFormat() throws Exception { // given @@ -494,6 +509,19 @@ private void withMergedValue(String payload) {} values = {@AsyncOperation.Headers.Header(name = "header")}))) private void withoutValue(String payload) {} + @AsyncListener( + operation = + @AsyncOperation( + channelName = "${test.property.test-channel}", + headers = + @AsyncOperation.Headers( + values = { + @AsyncOperation.Headers.Header( + name = "header", + value = {""}) + }))) + private void withEmptyValue(String payload) {} + @AsyncListener( operation = @AsyncOperation(