diff --git a/pom.xml b/pom.xml
index c90fd40..30d1a5f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
io.github.sashirestela
cleverclient
- 1.4.1
+ 1.4.2
jar
cleverclient
diff --git a/src/main/java/io/github/sashirestela/cleverclient/annotation/StreamType.java b/src/main/java/io/github/sashirestela/cleverclient/annotation/StreamType.java
index 3403977..a998d65 100644
--- a/src/main/java/io/github/sashirestela/cleverclient/annotation/StreamType.java
+++ b/src/main/java/io/github/sashirestela/cleverclient/annotation/StreamType.java
@@ -1,6 +1,6 @@
package io.github.sashirestela.cleverclient.annotation;
-import io.github.sashirestela.cleverclient.annotation.StreamType.List;
+import io.github.sashirestela.cleverclient.annotation.StreamType.StreamTypeArray;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
@@ -12,7 +12,7 @@
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
-@Repeatable(List.class)
+@Repeatable(StreamTypeArray.class)
public @interface StreamType {
Class> type();
@@ -22,7 +22,7 @@
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.ANNOTATION_TYPE })
- @interface List {
+ @interface StreamTypeArray {
StreamType[] value();
diff --git a/src/main/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStore.java b/src/main/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStore.java
index 61e8eaa..157f725 100644
--- a/src/main/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStore.java
+++ b/src/main/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStore.java
@@ -119,21 +119,23 @@ private List getParameters(Parameter[] javaParameters) {
private void validate(InterfaceMetadata interfaceMetadata) {
interfaceMetadata.getMethodBySignature().forEach((methodSignature, methodMetadata) -> {
- if (!methodMetadata.isDefault() && !methodMetadata.hasHttpAnnotation()) {
- throw new CleverClientException("Missing HTTP annotation for the method {0}.",
- methodMetadata.getName(), null);
- }
- var url = interfaceMetadata.getFullUrlByMethod(methodMetadata);
- var listPathParams = CommonUtil.findFullMatches(url, Constant.REGEX_PATH_PARAM_URL);
- if (!CommonUtil.isNullOrEmpty(listPathParams)) {
- listPathParams.forEach(pathParam -> methodMetadata.getPathParameters()
- .stream()
- .map(parameter -> parameter.getAnnotation().getValue())
- .filter(paramAnnotValue -> pathParam.equals(paramAnnotValue))
- .findFirst()
- .orElseThrow(() -> new CleverClientException(
- "Path param {0} in the url cannot find an annotated argument in the method {1}.",
- pathParam, methodMetadata.getName(), null)));
+ if (!methodMetadata.isDefault()) {
+ if (!methodMetadata.hasHttpAnnotation()) {
+ throw new CleverClientException("Missing HTTP annotation for the method {0}.",
+ methodMetadata.getName(), null);
+ }
+ var url = interfaceMetadata.getFullUrlByMethod(methodMetadata);
+ var listPathParams = CommonUtil.findFullMatches(url, Constant.REGEX_PATH_PARAM_URL);
+ if (!CommonUtil.isNullOrEmpty(listPathParams)) {
+ listPathParams.forEach(pathParam -> methodMetadata.getPathParameters()
+ .stream()
+ .map(parameter -> parameter.getAnnotation().getValue())
+ .filter(paramAnnotValue -> pathParam.equals(paramAnnotValue))
+ .findFirst()
+ .orElseThrow(() -> new CleverClientException(
+ "Path param {0} in the url cannot find an annotated argument in the method {1}.",
+ pathParam, methodMetadata.getName(), null)));
+ }
}
});
}
diff --git a/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java b/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java
index 5950900..2c3f6a1 100644
--- a/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java
+++ b/src/main/java/io/github/sashirestela/cleverclient/support/ReturnType.java
@@ -1,6 +1,7 @@
package io.github.sashirestela.cleverclient.support;
import io.github.sashirestela.cleverclient.annotation.StreamType;
+import io.github.sashirestela.cleverclient.annotation.StreamType.StreamTypeArray;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
@@ -44,19 +45,19 @@ public ReturnType(Method method) {
}
private void setClassByEventIfExists(Method method) {
- if (method.isAnnotationPresent(StreamType.List.class)) {
+ if (method.isAnnotationPresent(StreamTypeArray.class)) {
this.classByEvent = calculateClassByEvent(
- method.getDeclaredAnnotation(StreamType.List.class).value());
+ method.getDeclaredAnnotation(StreamTypeArray.class).value());
} else if (method.isAnnotationPresent(StreamType.class)) {
this.classByEvent = calculateClassByEvent(
new StreamType[] { method.getDeclaredAnnotation(StreamType.class) });
} else {
- var innerStreamTypeList = getInnerAnnotationIfExists(method, StreamType.List.class);
+ var innerStreamTypeList = getInnerAnnotationIfExists(method, StreamTypeArray.class);
if (innerStreamTypeList.isPresent()) {
this.classByEvent = calculateClassByEvent(
innerStreamTypeList.get()
.annotationType()
- .getDeclaredAnnotation(StreamType.List.class)
+ .getDeclaredAnnotation(StreamTypeArray.class)
.value());
} else {
var innerStreamType = getInnerAnnotationIfExists(method, StreamType.class);
diff --git a/src/test/java/io/github/sashirestela/cleverclient/http/ITest.java b/src/test/java/io/github/sashirestela/cleverclient/http/ITest.java
index d234f49..730c168 100644
--- a/src/test/java/io/github/sashirestela/cleverclient/http/ITest.java
+++ b/src/test/java/io/github/sashirestela/cleverclient/http/ITest.java
@@ -134,6 +134,18 @@ interface NotSavedService {
}
+ @Resource("/api/demos/{demoId}")
+ interface WithResourcePathParamAndDefaultMethods {
+
+ @GET
+ Demo getDemoPrimitive(@Path("demoId") Integer demoId);
+
+ default Demo getDemo(Integer demoId) {
+ return getDemoPrimitive(demoId);
+ }
+
+ }
+
@NoArgsConstructor
@AllArgsConstructor
@Getter
diff --git a/src/test/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStoreTest.java b/src/test/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStoreTest.java
index d2f1dd9..264dabb 100644
--- a/src/test/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStoreTest.java
+++ b/src/test/java/io/github/sashirestela/cleverclient/metadata/InterfaceMetadataStoreTest.java
@@ -12,6 +12,7 @@
import java.util.HashMap;
import static io.github.sashirestela.cleverclient.util.CommonUtil.createMapString;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -151,4 +152,9 @@ void shouldThrownExceptionWhenUrlPathParamAtMethodUnmatchesAnnotatedArguments()
exception.getMessage());
}
+ @Test
+ void shouldSaveSuccesfullyWhenInterfaceHasResourcePathParamAndDefaultMethod() {
+ assertDoesNotThrow(() -> store.save(ITest.WithResourcePathParamAndDefaultMethods.class));
+ }
+
}