Skip to content

Commit

Permalink
Remove processing for @RequestMapping with multiple attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
chao.wang committed Jan 9, 2025
1 parent f79d2ef commit 73855ff
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.openrewrite.java.spring.cloud2022;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.openrewrite.ExecutionContext;
Expand Down Expand Up @@ -79,19 +77,7 @@ public J.ClassDeclaration visitClassDeclaration(J.ClassDeclaration classDecl, Ex
} else if (requestMapping.getArguments().size() == 1) {
J.Assignment path = convertToPathAttribute(requestMapping.getArguments().get(0));
if (path != null && !hasPathAttribute(feignClient)) {
cd = withAddedAttributeToFeignClient(removeRequestMapping(classDecl), path);
}
} else {
List<Expression> args = new ArrayList<>(requestMapping.getArguments());
Iterator<Expression> iterator = args.iterator();
while (iterator.hasNext()) {
Expression argument = iterator.next();
J.Assignment path = convertToPathAttribute(argument);
if (path != null && !hasPathAttribute(feignClient)) {
iterator.remove();
cd = withRequestMappingAttributes(
withAddedAttributeToFeignClient(classDecl, path), args);
}
cd = addAttributeToFeignClient(removeRequestMapping(classDecl), path);
}
}
return cd;
Expand All @@ -116,17 +102,7 @@ private boolean hasPathAttribute(J.Annotation annotation) {
});
}

private J.ClassDeclaration withRequestMappingAttributes(J.ClassDeclaration classDeclaration, List<Expression> args) {
return classDeclaration.withLeadingAnnotations(
ListUtils.map(classDeclaration.getLeadingAnnotations(), a -> {
if (TypeUtils.isOfClassType(a.getType(), REQUEST_MAPPING)) {
return a.withArguments(args);
}
return a;
}));
}

private J.ClassDeclaration withAddedAttributeToFeignClient(J.ClassDeclaration classDeclaration, J.Assignment path) {
private J.ClassDeclaration addAttributeToFeignClient(J.ClassDeclaration classDeclaration, J.Assignment path) {
return classDeclaration.withLeadingAnnotations(
ListUtils.map(classDeclaration.getLeadingAnnotations(), a -> {
if (TypeUtils.isOfClassType(a.getType(), FEIGN_CLIENT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,6 @@ public interface MyServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/{postId}", produces = "application/json")
String getPostById(@PathVariable("postId") Long postId);
}
""",
"""
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.PathVariable;
@FeignClient(name = "myService", url = "http://localhost:8080", path = "/posts")
@RequestMapping(headers = "X-My-Header=MyValue")
public interface MyServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/{postId}", produces = "application/json")
String getPostById(@PathVariable("postId") Long postId);
}
"""
)
);
Expand Down

0 comments on commit 73855ff

Please sign in to comment.