Skip to content

Commit a261e78

Browse files
committed
open-api/kotlin: catch up
- kotlin: sync runApp funcion fix #3743 - open-api/kotlin: it fails to parse new server bootstrap fix #3746
1 parent 0e17a26 commit a261e78

File tree

12 files changed

+245
-8
lines changed

12 files changed

+245
-8
lines changed

modules/jooby-kotlin/src/main/kotlin/io/jooby/kt/Kooby.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,26 +313,50 @@ fun cors(init: Cors.() -> Unit): Cors {
313313
}
314314

315315
/** runApp: */
316+
// Consumers:
317+
fun runApp(args: Array<String>, init: Kooby.() -> Unit) {
318+
runApp(args, ExecutionMode.DEFAULT, init)
319+
}
320+
316321
fun runApp(args: Array<String>, mode: ExecutionMode, init: Kooby.() -> Unit) {
317-
configurePackage(init)
318-
Jooby.runApp(args, mode, fun() = Kooby(init))
322+
runApp(args, Server.loadServer(), mode, init)
319323
}
320324

321-
fun runApp(args: Array<String>, init: Kooby.() -> Unit) {
325+
fun runApp(args: Array<String>, server: Server, init: Kooby.() -> Unit) {
326+
runApp(args, server, ExecutionMode.DEFAULT, init)
327+
}
328+
329+
fun runApp(args: Array<String>, server: Server, mode: ExecutionMode, init: Kooby.() -> Unit) {
322330
configurePackage(init)
323-
Jooby.runApp(args, ExecutionMode.DEFAULT, fun() = Kooby(init))
331+
Jooby.runApp(args, server, mode, fun() = Kooby(init))
324332
}
325333

334+
// Suppliers:
326335
fun <T : Jooby> runApp(args: Array<String>, provider: () -> T) {
327336
runApp(args, ExecutionMode.DEFAULT, provider)
328337
}
329338

339+
fun <T : Jooby> runApp(args: Array<String>, server: Server, provider: () -> T) {
340+
runApp(args, server, ExecutionMode.DEFAULT, provider)
341+
}
342+
330343
fun <T : Jooby> runApp(args: Array<String>, mode: ExecutionMode, provider: () -> T) {
331-
Jooby.runApp(args, mode, provider)
344+
runApp(args, Server.loadServer(), mode, provider)
345+
}
346+
347+
fun <T : Jooby> runApp(
348+
args: Array<String>,
349+
server: Server,
350+
mode: ExecutionMode,
351+
provider: () -> T,
352+
) {
353+
configurePackage(provider)
354+
Jooby.runApp(args, server, mode, provider)
332355
}
333356

357+
// List of Suppliers:
334358
fun <T : Jooby> runApp(args: Array<String>, vararg provider: () -> T) {
335-
runApp(args, Server.loadServer(), ExecutionMode.DEFAULT, *provider)
359+
runApp(args, ExecutionMode.DEFAULT, *provider)
336360
}
337361

338362
fun <T : Jooby> runApp(args: Array<String>, mode: ExecutionMode, vararg provider: () -> T) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import static io.jooby.internal.openapi.TypeFactory.KT_FUN_1;
1515
import static io.jooby.internal.openapi.TypeFactory.OBJECT;
1616
import static io.jooby.internal.openapi.TypeFactory.STRING;
17-
import static io.jooby.internal.openapi.TypeFactory.STRING_ARRAY;
1817
import static org.objectweb.asm.Opcodes.GETSTATIC;
1918

2019
import java.lang.reflect.Modifier;
@@ -420,7 +419,8 @@ private List<OperationExt> routeHandler(ParserContext ctx, String prefix, Method
420419
ctx,
421420
prefix,
422421
node,
423-
signature.matches("runApp", STRING_ARRAY, TypeFactory.KT_FUN_0)));
422+
signature.endsWith("runApp", TypeFactory.KT_FUN_0)
423+
|| signature.endsWith("runApp", TypeFactory.KT_FUN_0_ARRAY)));
424424
} else if (signature.matches(Route.class, "produces", MediaType[].class)) {
425425
if (instructionTo != null) {
426426
OperationExt route = handlerList.get(handlerList.size() - 1);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ public boolean matches(String method, Type... parameterTypes) {
5353
return false;
5454
}
5555

56+
public boolean endsWith(String method, Type parameterType) {
57+
if (matches(method)) {
58+
return argumentTypes.length > 0
59+
&& argumentTypes[argumentTypes.length - 1]
60+
.getInternalName()
61+
.equals(parameterType.getInternalName());
62+
}
63+
return false;
64+
}
65+
5666
public boolean matches(Class owner, String method, Class... parameterTypes) {
5767
if (Type.getType(owner).equals(this.owner)) {
5868
return matches(method, parameterTypes);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class TypeFactory {
4646
public static final Type KT_KLASS = Type.getType("Lkotlin/reflect/KClass;");
4747

4848
public static final Type KT_FUN_0 = Type.getType("Lkotlin/jvm/functions/Function0;");
49+
public static final Type KT_FUN_0_ARRAY = Type.getType("[Lkotlin/jvm/functions/Function0;");
4950

5051
public static final Type KT_FUN_1 = Type.getType("Lkotlin/jvm/functions/Function1;");
5152

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package issues.i3746;
7+
8+
import static org.junit.jupiter.api.Assertions.assertEquals;
9+
10+
import io.jooby.openapi.OpenAPITest;
11+
import io.jooby.openapi.RouteIterator;
12+
import kt.i3746.RunAppInlineWithServerKt;
13+
import kt.i3746.RunAppInlineWithServerModeKt;
14+
import kt.i3746.RunAppWithServerKt;
15+
import kt.i3746.RunAppWithServerModeKt;
16+
17+
public class Issue3746 {
18+
19+
@OpenAPITest(value = RunAppWithServerKt.class)
20+
public void shouldParseRunAppWithServer(RouteIterator iterator) {
21+
checkApp(iterator);
22+
}
23+
24+
@OpenAPITest(value = RunAppInlineWithServerKt.class)
25+
public void shouldParseRunAppInlineWithServer(RouteIterator iterator) {
26+
checkApp(iterator);
27+
}
28+
29+
@OpenAPITest(value = RunAppInlineWithServerModeKt.class)
30+
public void shouldParseRunAppInlineWithServerMode(RouteIterator iterator) {
31+
checkApp(iterator);
32+
}
33+
34+
@OpenAPITest(value = RunAppWithServerModeKt.class)
35+
public void shouldParseRunAppWithServerMode(RouteIterator iterator) {
36+
checkApp(iterator);
37+
}
38+
39+
private static void checkApp(RouteIterator iterator) {
40+
iterator
41+
.next(
42+
route -> {
43+
assertEquals("GET /3746", route.toString());
44+
assertEquals(Object.class.getName(), route.getDefaultResponse().getJavaType());
45+
assertEquals("get3746", route.getOperationId());
46+
})
47+
.verify();
48+
}
49+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package kt.i3746
7+
8+
import io.jooby.kt.Kooby
9+
10+
class App3746 : Kooby({ get("/3746") { ctx.requestPath } })
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package kt.i3746
7+
8+
import io.jooby.kt.runApp
9+
10+
fun main(args: Array<String>) {
11+
runApp(args, Server3746()) { get("/3746") { ctx.requestPath } }
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package kt.i3746
7+
8+
import io.jooby.ExecutionMode
9+
import io.jooby.kt.runApp
10+
11+
fun main(args: Array<String>) {
12+
runApp(args, Server3746(), ExecutionMode.WORKER) { get("/3746") { ctx.requestPath } }
13+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package kt.i3746
7+
8+
import io.jooby.kt.runApp
9+
10+
fun main(args: Array<String>) {
11+
runApp(args, Server3746(), ::App3746)
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package kt.i3746
7+
8+
import io.jooby.ExecutionMode
9+
import io.jooby.kt.runApp
10+
11+
fun main(args: Array<String>) {
12+
runApp(args, Server3746(), ExecutionMode.EVENT_LOOP, ::App3746)
13+
}

0 commit comments

Comments
 (0)