Skip to content

Commit

Permalink
Fix List form handling in REST Client bean params
Browse files Browse the repository at this point in the history
Fixes: quarkusio#40324
(cherry picked from commit 9feb173)
  • Loading branch information
geoand authored and gsmet committed May 21, 2024
1 parent 7ae6146 commit 1c2c30f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,7 @@ A more full example of generated client (with sub-resource) can is at the bottom
// NOTE: don't use type here, because we're not going through the collection converters and stuff
Type parameterType = jandexMethod.parameterType(paramIdx);
addFormParam(methodCreator, param.name, methodCreator.getMethodParam(paramIdx),
parameterType, param.declaredType, param.signature, index,
parameterType, param.signature, index,
restClientInterface.getClassName(), methodCreator.getThis(), formParams,
getGenericTypeFromArray(methodCreator, methodGenericParametersField, paramIdx),
getAnnotationsFromArray(methodCreator, methodParamAnnotationsField, paramIdx),
Expand Down Expand Up @@ -2538,7 +2538,7 @@ private void addSubBeanParamData(MethodInfo jandexMethod, int paramIndex, Byteco
case FORM_PARAM:
FormParamItem formParam = (FormParamItem) item;
addFormParam(creator, formParam.getFormParamName(), formParam.extract(creator, param),
jandexMethod.parameterType(paramIndex), formParam.getParamType(), formParam.getParamSignature(),
formParam.getParamType(), formParam.getParamSignature(),
index,
restClientInterfaceClassName, client,
formParams,
Expand Down Expand Up @@ -2810,15 +2810,15 @@ private void addFormParam(BytecodeCreator methodCreator,
String paramName,
ResultHandle formParamHandle,
Type parameterType,
String parameterTypeStr,
String parameterSignature,
IndexView index,
String restClientInterfaceClassName, ResultHandle client, AssignableResultHandle formParams,
ResultHandle genericType,
ResultHandle parameterAnnotations, boolean multipart,
String partType, String partFilename, String errorLocation) {
if (multipart) {
handleMultipartField(paramName, partType, partFilename, parameterTypeStr, parameterSignature, formParamHandle,
handleMultipartField(paramName, partType, partFilename, parameterType.name().toString(), parameterSignature,
formParamHandle,
formParams, methodCreator,
client, restClientInterfaceClassName, parameterAnnotations, genericType,
errorLocation);
Expand Down Expand Up @@ -2846,7 +2846,8 @@ private void addFormParam(BytecodeCreator methodCreator,
creator.invokeInterfaceMethod(MULTIVALUED_MAP_ADD_ALL, formParams,
creator.load(paramName), convertedParamArray);
} else {
ResultHandle convertedFormParam = convertParamToString(creator, client, formParamHandle, parameterTypeStr,
ResultHandle convertedFormParam = convertParamToString(creator, client, formParamHandle,
parameterType.name().toString(),
genericType, parameterAnnotations);
BytecodeCreator parameterIsStringBranch = checkStringParam(creator, convertedFormParam,
restClientInterfaceClassName, errorLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URI;
import java.util.List;

import jakarta.ws.rs.BeanParam;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

Expand All @@ -26,26 +27,33 @@ public class FormListTest {
URI baseUri;

@Test
void testHeadersWithSubresource() {
void test() {
Client client = RestClientBuilder.newBuilder().baseUri(baseUri).build(Client.class);

assertThat(client.call(List.of("first", "second", "third"))).isEqualTo("first-second-third");
assertThat(client.call(List.of("first"))).isEqualTo("first");
Holder holder = new Holder();
holder.input2 = List.of("1", "2");
assertThat(client.call(List.of("first", "second", "third"), holder)).isEqualTo("first-second-third/1-2");
assertThat(client.call(List.of("first"), holder)).isEqualTo("first/1-2");
}

@Path("/test")
public static class Resource {

@POST
public String response(@RestForm List<String> input) {
return String.join("-", input);
public String response(@RestForm List<String> input, @RestForm List<String> input2) {
return String.join("-", input) + "/" + String.join("-", input2);
}
}

@Path("/test")
public interface Client {

@POST
String call(@RestForm List<String> input);
String call(@RestForm List<String> input, @BeanParam Holder holder);
}

public static class Holder {
@RestForm
public List<String> input2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ private static List<Item> parseInternal(ClassInfo beanParamClass, IndexView inde

resultList.addAll(paramItemsForFieldsAndMethods(beanParamClass, FORM_PARAM,
(annotationValue, fieldInfo) -> new FormParamItem(fieldInfo.name(), annotationValue,
fieldInfo.type().name().toString(), AsmUtil.getSignature(fieldInfo.type()),
fieldInfo.type(), AsmUtil.getSignature(fieldInfo.type()),
fieldInfo.name(),
partType(fieldInfo), fileName(fieldInfo), fieldInfo.hasDeclaredAnnotation(ENCODED),
new FieldExtractor(null, fieldInfo.name(), fieldInfo.declaringClass().name().toString())),
(annotationValue, getterMethod) -> new FormParamItem(getterMethod.name(), annotationValue,
getterMethod.returnType().name().toString(),
getterMethod.returnType(),
AsmUtil.getSignature(getterMethod.returnType()),
getterMethod.name(),
partType(getterMethod), fileName(getterMethod), getterMethod.hasDeclaredAnnotation(ENCODED),
Expand All @@ -176,13 +176,13 @@ private static List<Item> parseInternal(ClassInfo beanParamClass, IndexView inde
resultList.addAll(paramItemsForFieldsAndMethods(beanParamClass, REST_FORM_PARAM,
(annotationValue, fieldInfo) -> new FormParamItem(fieldInfo.name(),
annotationValue != null ? annotationValue : fieldInfo.name(),
fieldInfo.type().name().toString(), AsmUtil.getSignature(fieldInfo.type()),
fieldInfo.type(), AsmUtil.getSignature(fieldInfo.type()),
fieldInfo.name(),
partType(fieldInfo), fileName(fieldInfo), fieldInfo.hasDeclaredAnnotation(ENCODED),
new FieldExtractor(null, fieldInfo.name(), fieldInfo.declaringClass().name().toString())),
(annotationValue, getterMethod) -> new FormParamItem(getterMethod.name(),
annotationValue != null ? annotationValue : getterName(getterMethod),
getterMethod.returnType().name().toString(),
getterMethod.returnType(),
AsmUtil.getSignature(getterMethod.returnType()),
getterMethod.name(),
partType(getterMethod), fileName(getterMethod), getterMethod.hasDeclaredAnnotation(ENCODED),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.jboss.resteasy.reactive.client.processor.beanparam;

import org.jboss.jandex.Type;

public class FormParamItem extends Item {

private final String formParamName;
private final String paramType;
private final Type paramType;
private final String paramSignature;
private final String mimeType;
private final String fileName;
private final String sourceName;

public FormParamItem(String fieldName, String formParamName, String paramType, String paramSignature,
public FormParamItem(String fieldName, String formParamName, Type paramType, String paramSignature,
String sourceName,
String mimeType, String fileName,
boolean encoded,
Expand All @@ -27,7 +29,7 @@ public String getFormParamName() {
return formParamName;
}

public String getParamType() {
public Type getParamType() {
return paramType;
}

Expand Down

0 comments on commit 1c2c30f

Please sign in to comment.