Skip to content

Commit 16aa374

Browse files
committed
ApiTool kotlin: expand query/form bean object as single parameters jooby-project#1096
1 parent 33be08d commit 16aa374

3 files changed

Lines changed: 83 additions & 3 deletions

File tree

modules/jooby-apitool/src/test/java/issues/Issue1096.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import apps.Form1096;
88
import apps.Param1096;
99
import io.swagger.util.Yaml;
10+
import kt.App1096e;
11+
import kt.Query1096;
1012
import org.jooby.apitool.ApiParser;
1113
import org.jooby.apitool.RouteMethod;
1214
import org.jooby.apitool.RouteMethodAssert;
@@ -311,6 +313,62 @@ public void shouldExpandQueryBeanFromMvc() throws Exception {
311313
.build(null, routes)));
312314
}
313315

316+
@Test
317+
public void shouldExpandQueryBeanFromKotlin() throws Exception {
318+
List<RouteMethod> routes = new ApiParser(dir()).parseFully(new App1096e());
319+
320+
new RouteMethodAssert(routes)
321+
.next(r -> {
322+
r.returnType(String.class);
323+
r.method("GET");
324+
r.pattern("/1096/kt");
325+
r.description(null);
326+
r.summary(null);
327+
r.returns("java.lang.String");
328+
r.param(p -> {
329+
p.type(Query1096.class);
330+
p.name("params");
331+
p.kind(RouteParameter.Kind.QUERY);
332+
});
333+
})
334+
.done();
335+
336+
assertEquals("---\n"
337+
+ "swagger: \"2.0\"\n"
338+
+ "tags:\n"
339+
+ "- name: \"kt\"\n"
340+
+ "consumes:\n"
341+
+ "- \"application/json\"\n"
342+
+ "produces:\n"
343+
+ "- \"application/json\"\n"
344+
+ "paths:\n"
345+
+ " /1096/kt:\n"
346+
+ " get:\n"
347+
+ " tags:\n"
348+
+ " - \"kt\"\n"
349+
+ " operationId: \"getKt\"\n"
350+
+ " parameters:\n"
351+
+ " - name: \"name\"\n"
352+
+ " in: \"query\"\n"
353+
+ " required: true\n"
354+
+ " type: \"string\"\n"
355+
+ " - name: \"firstname\"\n"
356+
+ " in: \"query\"\n"
357+
+ " required: false\n"
358+
+ " type: \"string\"\n"
359+
+ " - name: \"picture.url\"\n"
360+
+ " in: \"query\"\n"
361+
+ " required: true\n"
362+
+ " type: \"string\"\n"
363+
+ " responses:\n"
364+
+ " 200:\n"
365+
+ " description: \"java.lang.String\"\n"
366+
+ " schema:\n"
367+
+ " type: \"string\"\n", Yaml
368+
.mapper().writer().withDefaultPrettyPrinter().writeValueAsString(new SwaggerBuilder()
369+
.build(null, routes)));
370+
}
371+
314372
private Path dir() {
315373
Path userdir = Paths.get(System.getProperty("user.dir"));
316374
if (!userdir.toString().endsWith("jooby-apitool")) {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package kt
2+
3+
import org.jooby.Kooby
4+
5+
data class Picture1096(val url: String)
6+
7+
data class Query1096(
8+
val name: String,
9+
val firstname: String?,
10+
val picture: Picture1096)
11+
12+
class App1096e : Kooby({
13+
path("/1096/kt") {
14+
get {
15+
val q = params(Query1096::class.java)
16+
q.toString()
17+
}
18+
}
19+
})

modules/jooby-lang-kotlin/src/main/kotlin/org/jooby/Jooby.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.jooby
22

3-
import kotlin.reflect.KClass
43
import org.jooby.spi.Server
5-
import java.util.SortedSet
6-
import com.sun.xml.internal.bind.v2.schemagen.episode.Klass
4+
import java.util.*
5+
import kotlin.reflect.KClass
76

87
@DslMarker
98
annotation class DslJooby
@@ -466,3 +465,7 @@ inline fun <reified T> Request.header(name: String): T {
466465
inline fun <reified T> Request.body(): T {
467466
return body().to(T::class.java)
468467
}
468+
469+
inline fun <reified T> Request.params(): T {
470+
return params(T::class.java)
471+
}

0 commit comments

Comments
 (0)