Skip to content

Commit 58357dd

Browse files
committed
Also handle J.NewArray in MigrateRequestMappingOnFeignClient
Fixes #666
1 parent d0364cb commit 58357dd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/main/java/org/openrewrite/java/spring/cloud2022/MigrateRequestMappingOnFeignClient.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.openrewrite.java.tree.J;
2929
import org.openrewrite.java.tree.TypeUtils;
3030

31+
import java.util.List;
32+
3133
public class MigrateRequestMappingOnFeignClient extends Recipe {
3234

3335
private static final String FEIGN_CLIENT = "org.springframework.cloud.openfeign.FeignClient";
@@ -122,6 +124,11 @@ private String getPathValue(Expression arg) {
122124
}
123125
}
124126
}
127+
} else if (arg instanceof J.NewArray) {
128+
List<Expression> initializer = ((J.NewArray) arg).getInitializer();
129+
if (initializer != null && initializer.size() == 1) {
130+
return getPathValue(initializer.get(0));
131+
}
125132
}
126133
return null;
127134
}

src/test/java/org/openrewrite/java/spring/cloud2022/MigrateRequestMappingOnFeignClientTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,43 @@ public interface MyServiceClient {
110110
);
111111
}
112112

113+
@Test
114+
void requestMappingWithDefaultAttributeNameAndArray() {
115+
rewriteRun(
116+
//language=java
117+
java(
118+
"""
119+
import org.springframework.cloud.openfeign.FeignClient;
120+
import org.springframework.web.bind.annotation.RequestMapping;
121+
import org.springframework.web.bind.annotation.RequestMethod;
122+
import org.springframework.web.bind.annotation.PathVariable;
123+
import org.springframework.web.bind.annotation.GetMapping;
124+
125+
@FeignClient(name = "myService", url = "http://localhost:8080")
126+
@RequestMapping({"/posts"})
127+
public interface MyServiceClient {
128+
129+
@GetMapping(value = "/{postId}", produces = "application/json")
130+
String getPostById(@PathVariable("postId") Long postId);
131+
}
132+
""",
133+
"""
134+
import org.springframework.cloud.openfeign.FeignClient;
135+
import org.springframework.web.bind.annotation.RequestMethod;
136+
import org.springframework.web.bind.annotation.PathVariable;
137+
import org.springframework.web.bind.annotation.GetMapping;
138+
139+
@FeignClient(path = "/posts", name = "myService", url = "http://localhost:8080")
140+
public interface MyServiceClient {
141+
142+
@GetMapping(value = "/{postId}", produces = "application/json")
143+
String getPostById(@PathVariable("postId") Long postId);
144+
}
145+
"""
146+
)
147+
);
148+
}
149+
113150
@Test
114151
void requestMappingWithValueAttributeName() {
115152
rewriteRun(

0 commit comments

Comments
 (0)