Skip to content

Commit 56d42b2

Browse files
committed
ApiTool does not work with Sub Applications fix #1300
1 parent 13b1020 commit 56d42b2

File tree

4 files changed

+93
-1
lines changed

4 files changed

+93
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,25 @@ private List<Object> kotlinLambda(final ClassLoader loader, final ClassNode owne
748748
.filter(and(is(MethodInsnNode.class), opcode(INVOKESPECIAL)))
749749
.findFirst()
750750
.map(MethodInsnNode.class::cast)
751-
.ifPresent(n -> result.addAll(lambdas(loader, loadClass(n.owner))));
751+
.ifPresent(n -> {
752+
List<Object> rlist = lambdas(loader, loadClass(n.owner));
753+
Insn.ldcFor(n).stream()
754+
.map(e -> e.cst.toString())
755+
.findFirst()
756+
.ifPresent(prefix -> {
757+
IntStream.range(0, rlist.size())
758+
.forEach(i -> {
759+
Object o = rlist.get(i);
760+
if (o instanceof Lambda) {
761+
rlist.set(i, ((Lambda) o).prefix(prefix));
762+
} else {
763+
RouteMethod r = (RouteMethod) o;
764+
r.pattern(prefix + r.pattern());
765+
}
766+
});
767+
});
768+
result.addAll(rlist);
769+
});
752770
})
753771
// path(String) {...}
754772
.on(path(loader, "org.jooby.Kooby"), it -> {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package issues;
2+
3+
import kt.App1300;
4+
import org.jooby.apitool.ApiParser;
5+
import org.jooby.apitool.ApiToolFeature;
6+
import org.jooby.apitool.RouteMethod;
7+
import org.junit.Test;
8+
9+
import java.util.List;
10+
11+
import static org.junit.Assert.assertEquals;
12+
13+
public class Issue1300 extends ApiToolFeature {
14+
15+
@Test
16+
public void apitoolDoesNotListMvcNamespaced () throws Exception {
17+
List<RouteMethod> routes = new ApiParser(dir()).parseFully(new App1300());
18+
19+
assertEquals("---\n"
20+
+ "swagger: \"2.0\"\n"
21+
+ "tags:\n"
22+
+ "- name: \"/route\"\n"
23+
+ "- name: \"/subroute/hello\"\n"
24+
+ "consumes:\n"
25+
+ "- \"application/json\"\n"
26+
+ "produces:\n"
27+
+ "- \"application/json\"\n"
28+
+ "paths:\n"
29+
+ " /route:\n"
30+
+ " get:\n"
31+
+ " tags:\n"
32+
+ " - \"/route\"\n"
33+
+ " operationId: \"getRoute\"\n"
34+
+ " parameters: []\n"
35+
+ " responses:\n"
36+
+ " 200:\n"
37+
+ " description: \"int\"\n"
38+
+ " schema:\n"
39+
+ " type: \"integer\"\n"
40+
+ " format: \"int32\"\n"
41+
+ " /subroute/hello:\n"
42+
+ " get:\n"
43+
+ " tags:\n"
44+
+ " - \"/subroute/hello\"\n"
45+
+ " operationId: \"getSubroutehello\"\n"
46+
+ " parameters: []\n"
47+
+ " responses:\n"
48+
+ " 200:\n"
49+
+ " description: \"String\"\n"
50+
+ " schema:\n"
51+
+ " type: \"string\"\n", yaml(swagger(routes), false));
52+
}
53+
54+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package kt
2+
3+
import org.jooby.Kooby
4+
5+
class App1300 : Kooby({
6+
get("route") {
7+
123
8+
}
9+
10+
use("subroute", SubRoute1300())
11+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package kt
2+
3+
import org.jooby.Kooby
4+
5+
class SubRoute1300 : Kooby({
6+
get("hello") {
7+
"word"
8+
}
9+
})

0 commit comments

Comments
 (0)