Skip to content

Commit 125fcc8

Browse files
committed
Parameters that are called "name" cannot have other annotations on them besides *Param fix #2352
1 parent f864910 commit 125fcc8

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.jooby.i2352;
2+
3+
import java.util.Optional;
4+
5+
import javax.annotation.Nonnull;
6+
import javax.annotation.Nullable;
7+
8+
import io.jooby.annotations.FormParam;
9+
import io.jooby.annotations.POST;
10+
11+
public class C2352 {
12+
@POST("/2352/nonnull")
13+
public String nonnull(@Nonnull @FormParam String name) {
14+
return name;
15+
}
16+
17+
@POST("/2352/nullable")
18+
public String nullable(@Nullable @FormParam String name) {
19+
return String.valueOf(name);
20+
}
21+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.jooby.i2352;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import io.jooby.junit.ServerTest;
6+
import io.jooby.junit.ServerTestRunner;
7+
import okhttp3.MultipartBody;
8+
9+
public class Issue2352 {
10+
@ServerTest
11+
public void shouldNotIgnoreAnnotationOnParam(ServerTestRunner runner) {
12+
runner.define(app -> {
13+
app.mvc(new C2352());
14+
app.error((ctx, cause, code) -> {
15+
ctx.send(cause.getMessage());
16+
});
17+
}).ready(http -> {
18+
19+
String name = getClass().getSimpleName();
20+
http.post("/2352/nonnull", new MultipartBody.Builder()
21+
.setType(MultipartBody.FORM)
22+
.addFormDataPart("noname", name)
23+
.build(), rsp -> {
24+
assertEquals(400, rsp.code());
25+
assertEquals("Missing value: 'name'", rsp.body().string());
26+
});
27+
28+
http.post("/2352/nonnull", new MultipartBody.Builder()
29+
.setType(MultipartBody.FORM)
30+
.addFormDataPart("name", name)
31+
.build(), rsp -> {
32+
assertEquals(name, rsp.body().string());
33+
});
34+
35+
http.post("/2352/nullable", new MultipartBody.Builder()
36+
.setType(MultipartBody.FORM)
37+
.addFormDataPart("noname", name)
38+
.build(), rsp -> {
39+
assertEquals(200, rsp.code());
40+
assertEquals("null", rsp.body().string());
41+
});
42+
});
43+
}
44+
}

0 commit comments

Comments
 (0)