Skip to content

Commit bcbd615

Browse files
haggishjknack
authored andcommitted
ApiTool to interpret path parameters correctly in POSTs without Body annotation fix jooby-project#1056 (jooby-project#1058)
1 parent c8c7bed commit bcbd615

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

modules/jooby-apitool/src/main/java/org/jooby/internal/apitool/BytecodeRouteParser.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,11 +1209,14 @@ private static RouteParameter toRouteParameter(String pattern, final Parameter p
12091209
.isPresent())
12101210
.findFirst()
12111211
.isPresent();
1212+
if (isPathParam(pattern, pname)) {
1213+
return RouteParameter.Kind.PATH;
1214+
}
12121215
boolean formLike = !hasBody && p.getDeclaringExecutable().getAnnotation(POST.class) != null;
12131216
if (formLike) {
12141217
return RouteParameter.Kind.FORM;
12151218
}
1216-
return isPathParam(pattern, pname) ? RouteParameter.Kind.PATH : RouteParameter.Kind.QUERY;
1219+
return RouteParameter.Kind.QUERY;
12171220
};
12181221
return new RouteParameter(pname, kind.get(), p.getParameterizedType(), null);
12191222
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package apps;
2+
3+
import org.jooby.Jooby;
4+
import org.jooby.Upload;
5+
import org.jooby.mvc.POST;
6+
import org.jooby.mvc.Path;
7+
8+
public class App1056 extends Jooby {
9+
10+
{
11+
use(CatResource.class);
12+
}
13+
14+
@Path("/api/inner/cat")
15+
public static class CatResource {
16+
17+
@Path("/:name/pat")
18+
@POST
19+
public void pat(final String name) {
20+
}
21+
22+
@Path("/:name/feed")
23+
@POST
24+
public void feed(final String name, final Upload food) {
25+
}
26+
}
27+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.jooby.apitool;
2+
3+
import apps.App1056;
4+
import org.junit.Test;
5+
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
import org.jooby.Upload;
9+
10+
11+
public class Issue1056 {
12+
13+
@Test
14+
public void shouldWorkWithBodilessAndMultiformPosts() throws Exception {
15+
new RouteMethodAssert(new ApiParser(dir()).parseFully(new App1056()))
16+
.next(r -> {
17+
r.returnType(void.class);
18+
r.pattern("/api/inner/cat/{name}/pat");
19+
r.method("POST");
20+
r.param(p -> {
21+
p.name("name")
22+
.type(String.class)
23+
.kind(RouteParameter.Kind.PATH);
24+
});
25+
})
26+
.next(r -> {
27+
r.returnType(void.class);
28+
r.pattern("/api/inner/cat/{name}/feed");
29+
r.method("POST");
30+
r.param(p -> {
31+
p.name("name")
32+
.type(String.class)
33+
.kind(RouteParameter.Kind.PATH);
34+
}).param(p -> {
35+
p.name("food")
36+
.type(Upload.class)
37+
.kind(RouteParameter.Kind.FILE);
38+
});
39+
})
40+
.done();
41+
}
42+
43+
private Path dir() {
44+
Path userdir = Paths.get(System.getProperty("user.dir"));
45+
if (!userdir.toString().endsWith("jooby-apitool")) {
46+
userdir = userdir.resolve("modules").resolve("jooby-apitool");
47+
}
48+
return userdir;
49+
}
50+
}

0 commit comments

Comments
 (0)