Skip to content

Commit 06af18a

Browse files
committed
#65 - [client api] Bug with @Form @post with path parameter included as formParam()
1 parent 39c9cdc commit 06af18a

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

http-generator-client/src/main/java/io/avaje/http/generator/client/ClientMethodWriter.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void write() {
8181
writeHeaders();
8282
writePaths(segments);
8383
writeQueryParams(pathSegments);
84-
writeFormParams();
84+
writeFormParams(pathSegments);
8585
writeBody();
8686

8787
WebMethod webMethod = method.getWebMethod();
@@ -174,20 +174,29 @@ private void writeHeaders() {
174174
}
175175
}
176176

177-
private void writeFormParams() {
177+
private void writeFormParams(PathSegments segments) {
178178
for (MethodParam param : method.getParams()) {
179+
final String varName = param.getName();
179180
ParamType paramType = param.getParamType();
180-
if (paramType == ParamType.FORMPARAM) {
181-
if (isMap(param)) {
182-
writer.append(" .formParam(%s)", param.getName()).eol();
183-
} else {
184-
writer.append(" .formParam(\"%s\", %s)", param.getParamName(), param.getName()).eol();
185-
}
186-
} else if (paramType == ParamType.FORM) {
187-
TypeElement formBeanType = ctx.getTypeElement(param.getRawType());
188-
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.getName(), param.getShortType(), ParamType.FORMPARAM);
189-
form.writeFormParams(writer);
181+
PathSegments.Segment segment = segments.segment(varName);
182+
if (segment == null) {
183+
// not a path or matrix parameter
184+
writeFormParam(param, paramType);
185+
}
186+
}
187+
}
188+
189+
private void writeFormParam(MethodParam param, ParamType paramType) {
190+
if (paramType == ParamType.FORMPARAM) {
191+
if (isMap(param)) {
192+
writer.append(" .formParam(%s)", param.getName()).eol();
193+
} else {
194+
writer.append(" .formParam(\"%s\", %s)", param.getParamName(), param.getName()).eol();
190195
}
196+
} else if (paramType == ParamType.FORM) {
197+
TypeElement formBeanType = ctx.getTypeElement(param.getRawType());
198+
BeanParamReader form = new BeanParamReader(ctx, formBeanType, param.getName(), param.getShortType(), ParamType.FORMPARAM);
199+
form.writeFormParams(writer);
191200
}
192201
}
193202

tests/test-client/src/main/java/org/example/JunkApi.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.example;
22

33
import io.avaje.http.api.Client;
4+
import io.avaje.http.api.Form;
45
import io.avaje.http.api.Get;
56
import io.avaje.http.api.Post;
67
import io.avaje.http.client.HttpCall;
@@ -131,4 +132,8 @@ public interface JunkApi {
131132

132133
@Post("/{id}/foo/{name}")
133134
HttpResponse<Path> reqBodyResHand2(HttpResponse.BodyHandler<Path> handler, HttpRequest.BodyPublisher body, String id, String name, String other);
135+
136+
@Form
137+
@Post("foo/{email}")
138+
void postFormWithPath(String email, String name, String other);
134139
}

0 commit comments

Comments
 (0)