Skip to content

Commit 858b6d6

Browse files
committed
openapi: api doc generator doesn't respect mount() construction fix #2046
1 parent edd622d commit 858b6d6

File tree

4 files changed

+65
-5
lines changed

4 files changed

+65
-5
lines changed

modules/jooby-openapi/src/main/java/io/jooby/internal/openapi/RouteParser.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,12 @@ private List<OperationExt> routeHandler(ParserContext ctx, String prefix,
273273
handlerList.addAll(AnnotationParser.parse(ctx, prefix, signature, (MethodInsnNode) it));
274274
} else if (signature.matches("<init>", KT_FUN_1)) {
275275
handlerList.addAll(kotlinHandler(ctx, null, prefix, node));
276-
} else if (signature.matches("use", Router.class)) {
277-
handlerList.addAll(useRouter(ctx, prefix, node, findRouterInstruction(node)));
278-
} else if (signature.matches("use", String.class, Router.class)) {
276+
} else if (signature.matches("use", Router.class) || signature.matches("mount", Router.class)) {
277+
handlerList.addAll(mountRouter(ctx, prefix, node, findRouterInstruction(node)));
278+
} else if (signature.matches("use", String.class, Router.class) || signature.matches("mount", String.class, Router.class)) {
279279
AbstractInsnNode routerInstruction = findRouterInstruction(node);
280280
String pattern = routePattern(node, node);
281-
handlerList.addAll(useRouter(ctx, path(prefix, pattern), node, routerInstruction));
281+
handlerList.addAll(mountRouter(ctx, path(prefix, pattern), node, routerInstruction));
282282
} else if (signature.matches("path", String.class, Runnable.class)
283283
|| signature.matches("routes", Runnable.class)) {
284284
boolean routes = signature.matches("routes", Runnable.class);
@@ -504,7 +504,7 @@ private AbstractInsnNode findRouterInstruction(MethodInsnNode node) {
504504
"Unsupported router type: " + InsnSupport.toString(node)));
505505
}
506506

507-
private List<OperationExt> useRouter(ParserContext ctx, String prefix,
507+
private List<OperationExt> mountRouter(ParserContext ctx, String prefix,
508508
MethodInsnNode node, AbstractInsnNode routerInstruction) {
509509
Type router;
510510
if (routerInstruction instanceof TypeInsnNode) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package issues.i2046;
2+
3+
import io.jooby.Jooby;
4+
5+
public class App2046 extends Jooby {
6+
{
7+
get("/2046", ctx -> "..");
8+
9+
mount("/b", new App2046b());
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package issues.i2046;
2+
3+
import io.jooby.Jooby;
4+
5+
public class App2046b extends Jooby {
6+
7+
{
8+
get("/2046b", ctx -> "..");
9+
}
10+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package issues.i2046;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import io.jooby.openapi.OpenAPIResult;
6+
import io.jooby.openapi.OpenAPITest;
7+
import kt.issues.i2004.App2004;
8+
9+
public class Issue2046 {
10+
@OpenAPITest(value = App2046.class)
11+
public void shouldSupportMountOperation(OpenAPIResult result) {
12+
assertEquals("openapi: 3.0.1\n"
13+
+ "info:\n"
14+
+ " title: 2046 API\n"
15+
+ " description: 2046 API description\n"
16+
+ " version: \"1.0\"\n"
17+
+ "paths:\n"
18+
+ " /2046:\n"
19+
+ " get:\n"
20+
+ " operationId: get2046\n"
21+
+ " responses:\n"
22+
+ " \"200\":\n"
23+
+ " description: Success\n"
24+
+ " content:\n"
25+
+ " application/json:\n"
26+
+ " schema:\n"
27+
+ " type: string\n"
28+
+ " /b/2046b:\n"
29+
+ " get:\n"
30+
+ " operationId: getB2046b\n"
31+
+ " responses:\n"
32+
+ " \"200\":\n"
33+
+ " description: Success\n"
34+
+ " content:\n"
35+
+ " application/json:\n"
36+
+ " schema:\n"
37+
+ " type: string\n", result.toYaml());
38+
}
39+
}

0 commit comments

Comments
 (0)