Skip to content

Commit af95a1e

Browse files
committed
Jex generation using {} rather than colon based path parameters
1 parent c082cc8 commit af95a1e

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ControllerMethodWriter {
3131
void write(boolean requestScoped) {
3232

3333
final PathSegments segments = method.getPathSegments();
34-
final String fullPath = segments.fullPathColon();
34+
final String fullPath = segments.fullPath();
3535

3636
writer.append(" routing.%s(\"%s\", ctx -> {", webMethod.name().toLowerCase(), fullPath).eol();
3737
writer.append(" ctx.status(%s);", method.getStatusCode()).eol();
@@ -95,9 +95,9 @@ private void writeContextReturn() {
9595
} else if (produces.equalsIgnoreCase(MediaType.TEXT_HTML)) {
9696
writer.append("ctx.html(");
9797
} else if (produces.equalsIgnoreCase(MediaType.TEXT_PLAIN)) {
98-
writer.append("ctx.contentType(\"text/plain\").result(");
98+
writer.append("ctx.text(");
9999
} else {
100-
writer.append("ctx.contentType(\"%s\").result(", produces);
100+
writer.append("ctx.contentType(\"%s\").write(", produces);
101101
}
102102
}
103103
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.avaje.http.api.Controller;
44
import io.avaje.http.api.Get;
55
import io.avaje.http.api.Path;
6+
import io.avaje.http.api.Produces;
67

78
@Controller
89
@Path("/")
@@ -15,4 +16,16 @@ HelloDto getHello() {
1516
dto.name = "rob";
1617
return dto;
1718
}
19+
20+
@Produces("text/plain")
21+
@Get("plain")
22+
String getText() {
23+
return "something";
24+
}
25+
26+
@Produces("text/plain")
27+
@Get("other/{name}")
28+
String name(String name) {
29+
return "hi "+name;
30+
}
1831
}

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import io.avaje.http.client.HttpClientContext;
44
import org.junit.jupiter.api.Test;
55

6+
import java.net.http.HttpResponse;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
69
import static org.junit.jupiter.api.Assertions.assertEquals;
710

811
class HelloControllerTest extends BaseWebTest {
@@ -16,4 +19,20 @@ void getHello() {
1619
assertEquals(42, hello.id);
1720
assertEquals("rob", hello.name);
1821
}
22+
23+
@Test
24+
void getPlain() {
25+
26+
final HttpResponse<String> res = client.request().path("plain").get().asString();
27+
28+
assertEquals("something", res.body());
29+
assertThat(res.headers().firstValue("content-type").get()).startsWith("text/plain;");
30+
}
31+
32+
@Test
33+
void getName() {
34+
35+
assertEquals("hi bazz", client.request().path("other/bazz").get().asString().body());
36+
assertEquals("hi bax", client.request().path("other/bax").get().asString().body());
37+
}
1938
}

0 commit comments

Comments
 (0)