Skip to content

Commit

Permalink
Resteasy Reactive: Inspect class tree for @BeanParam to find annotations
Browse files Browse the repository at this point in the history
The method `ClassInfo.annotations` only returns the annotations at the current class level. 
This PR makes the parser method to also find the inherited annotations.
Fix quarkusio#21759
  • Loading branch information
Sgitario committed Nov 29, 2021
1 parent ebd6d37 commit b44601a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ void shouldPassPathParamFromBeanParamAndMethod() {
assertThat(client.getWithBeanParam("foo", new MyBeanParam("123"))).isEqualTo("it works with method too!");
}

@Test
void shouldResolvePathParamsWhenBeanParamClassExtendsAnother() {
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);
assertThat(client.getWithBeanParamInheritance(new MyChildBeanParam("child", "123"))).isEqualTo(
"it works with inheritance too!");
}

@Path("/my/{id}/resource")
public interface Client {
@GET
Expand All @@ -43,6 +50,10 @@ public interface Client {
@GET
@Path("/{name}")
String getWithBeanParam(@PathParam("name") String name, @BeanParam MyBeanParam beanParam);

@GET
@Path("/item/{base}")
String getWithBeanParamInheritance(@BeanParam MyChildBeanParam beanParam);
}

public static class MyBeanParam {
Expand All @@ -58,6 +69,40 @@ public String getId() {
}
}

public static class MyChildBeanParam extends MyBeanParam {
private final String base;

public MyChildBeanParam(String base, String id) {
super(id);
this.base = base;
}

@PathParam("base")
public String getBase() {
return base;
}
}

public static class TestMyChildBeanParam {
private final String id;
private final String base;

public TestMyChildBeanParam(String base, String id) {
this.id = id;
this.base = base;
}

@PathParam("id")
public String getId() {
return id;
}

@PathParam("base")
public String getBase() {
return base;
}
}

@Path("/my/123/resource")
public static class Resource {
@GET
Expand All @@ -70,5 +115,11 @@ public String get() {
public String getWithLongerPath() {
return "it works with method too!";
}

@Path("/item/child")
@GET
public String getWithInheritance() {
return "it works with inheritance too!";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@
import org.jboss.jandex.IndexView;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;
import org.jboss.resteasy.reactive.common.processor.JandexUtil;

public class BeanParamParser {

public static List<Item> parse(ClassInfo beanParamClass, IndexView index) {
List<Item> resultList = new ArrayList<>();

// Parse class tree recursively
if (!JandexUtil.DOTNAME_OBJECT.equals(beanParamClass.superName())) {
resultList.addAll(parse(index.getClassByName(beanParamClass.superName()), index));
}

Map<DotName, List<AnnotationInstance>> annotations = beanParamClass.annotations();
List<AnnotationInstance> queryParams = annotations.get(QUERY_PARAM);
if (queryParams != null) {
Expand Down

0 comments on commit b44601a

Please sign in to comment.