Skip to content

Commit 46bd456

Browse files
committed
#72 - Add support for withDefault() with Jex generation
1 parent c5a6de9 commit 46bd456

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

http-generator-jex/src/main/java/io/avaje/http/generator/jex/JexAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ public void writeReadParameter(Append writer, ParamType paramType, String paramN
5959

6060
@Override
6161
public void writeReadParameter(Append writer, ParamType paramType, String paramName, String paramDefault) {
62-
writer.append("ctx.%s(\"%s\",\"%s\")", paramType, paramName, paramDefault);
62+
writer.append("withDefault(ctx.%s(\"%s\"), \"%s\")", paramType, paramName, paramDefault);
6363
}
6464
}

tests/test-jex/src/main/java/org/example/web/HelloController.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ String name(String name) {
3131
return "hi " + name;
3232
}
3333

34+
@Produces("text/plain")
35+
@Get("withDefault/{name}")
36+
String withDefault(String name, @Default("42") String limit) {
37+
return "name|" + name+";limit|"+limit;
38+
}
39+
3440
@Produces("text/plain")
3541
@Get("splat/{name}/<s0>/other/<s1>")
3642
String splat(String name, Context ctx) {

tests/test-jex/src/main/resources/public/openapi.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,39 @@
157157
}
158158
}
159159
}
160+
},
161+
"/withDefault/{name}" : {
162+
"get" : {
163+
"tags" : [ ],
164+
"summary" : "",
165+
"description" : "",
166+
"parameters" : [ {
167+
"name" : "name",
168+
"in" : "path",
169+
"required" : true,
170+
"schema" : {
171+
"type" : "string"
172+
}
173+
}, {
174+
"name" : "limit",
175+
"in" : "query",
176+
"schema" : {
177+
"type" : "string"
178+
}
179+
} ],
180+
"responses" : {
181+
"200" : {
182+
"description" : "",
183+
"content" : {
184+
"text/plain" : {
185+
"schema" : {
186+
"type" : "string"
187+
}
188+
}
189+
}
190+
}
191+
}
192+
}
160193
}
161194
},
162195
"components" : {

tests/test-jex/src/test/java/org/example/web/HelloControllerTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ void getHello() {
2424

2525
@Test
2626
void getPlain() {
27-
2827
final HttpResponse<String> res = client.request().path("plain").GET().asString();
2928

3029
assertEquals("something", res.body());
@@ -33,11 +32,17 @@ void getPlain() {
3332

3433
@Test
3534
void getName() {
36-
3735
assertEquals("hi bazz", client.request().path("other/bazz").GET().asString().body());
3836
assertEquals("hi bax", client.request().path("other/bax").GET().asString().body());
3937
}
4038

39+
@Test
40+
void withDefault() {
41+
assertEquals("name|bazz;limit|42", client.request().path("withDefault/bazz").GET().asString().body());
42+
assertEquals("name|bazz;limit|10", client.request().path("withDefault/bazz").queryParam("limit", 10).GET().asString().body());
43+
assertEquals("name|foo;limit|11", client.request().path("withDefault/foo").queryParam("limit", 11).queryParam("limit", 12).GET().asString().body());
44+
}
45+
4146
@Test
4247
void splat() {
4348
assertEquals("got name:one splat0:a/b splat1:x/y/z", client.request().path("splat/one/a/b/other/x/y/z").GET().asString().body());
@@ -48,10 +53,8 @@ void splat2() {
4853
assertEquals("got name:one splat0:a/b splat1:x/y/z", client.request().path("splat2/one/a/b/other/x/y/z").GET().asString().body());
4954
}
5055

51-
5256
@Test
5357
void validation() {
54-
5558
HelloDto helloDto = new HelloDto();
5659
helloDto.id = 42;
5760

@@ -65,7 +68,6 @@ void validation() {
6568

6669
@Test
6770
void validation_expect_HttpException() {
68-
6971
HelloDto helloDto = new HelloDto();
7072
helloDto.id = 42;
7173

0 commit comments

Comments
 (0)