Skip to content

Commit 48ba718

Browse files
authored
Improve the compile error message when we think @BeanParam is needed (#582)
1 parent 886785d commit 48ba718

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

Diff for: http-generator-core/src/main/java/io/avaje/http/generator/core/MethodReader.java

+12-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static io.avaje.http.generator.core.ProcessingContext.platform;
66
import static io.avaje.http.generator.core.ProcessingContext.superMethods;
77

8+
import java.text.MessageFormat;
89
import java.util.*;
910
import java.util.function.Consumer;
1011
import java.util.function.Function;
@@ -343,18 +344,23 @@ void read() {
343344
final MethodParam param = new MethodParam(p, type, rawType, defaultParamType, formMarker);
344345
params.add(param);
345346

346-
if (CoreWebMethod.GET.equals(webMethod)
347-
&& param.isBody()
348-
&& !"java.util.Map".equals(param.utype().mainType())
349-
&& !"ClientPlatformAdapter"
350-
.equals(ProcessingContext.platform().getClass().getSimpleName())) {
351-
logError(p, "Missing @BeanParam annotation");
347+
if (CoreWebMethod.GET.equals(webMethod) && isBodyParam(param)) {
348+
logError(p, MessageFormat.format("Unsure how to populate {0} parameter for this @Get request. " +
349+
"Perhaps it should be a @Post instead? or otherwise add @BeanParam to {0} to populate it from path parameters.",
350+
param.name()));
352351
}
353352

354353
param.addImports(bean);
355354
}
356355
}
357356

357+
private static boolean isBodyParam(MethodParam param) {
358+
return param.isBody()
359+
&& !"java.util.Map".equals(param.utype().mainType())
360+
&& !"ClientPlatformAdapter"
361+
.equals(ProcessingContext.platform().getClass().getSimpleName());
362+
}
363+
358364
public void buildApiDoc() {
359365
buildApiDocumentation();
360366
}

Diff for: http-generator-helidon/src/main/java/io/avaje/http/generator/helidon/nima/ControllerMethodWriter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,9 @@ private boolean usesFormParams() {
375375
}
376376

377377
private boolean usesQueryParams() {
378-
return method.params().stream().anyMatch(p -> ParamType.QUERYPARAM.equals(p.paramType()));
378+
return method.params().stream().anyMatch(p ->
379+
ParamType.QUERYPARAM.equals(p.paramType())
380+
|| ParamType.BEANPARAM.equals(p.paramType()));
379381
}
380382

381383
private void writeContextReturn(String indent) {

Diff for: tests/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<jackson.version>2.18.3</jackson.version>
1818
<jex.version>3.0-RC22</jex.version>
1919
<avaje-inject.version>11.3</avaje-inject.version>
20-
<nima.version>4.2.0</nima.version>
20+
<helidon.version>4.2.0</helidon.version>
2121
<javalin.version>6.5.0</javalin.version>
2222
</properties>
2323

Diff for: tests/test-nima-jsonb/pom.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
<dependency>
3737
<groupId>io.helidon.webserver</groupId>
3838
<artifactId>helidon-webserver</artifactId>
39-
<version>${nima.version}</version>
39+
<version>${helidon.version}</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>io.helidon.http.media</groupId>
4343
<artifactId>helidon-http-media-jsonb</artifactId>
44-
<version>${nima.version}</version>
44+
<version>${helidon.version}</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>io.avaje</groupId>
@@ -54,7 +54,7 @@
5454
<artifactId>jstachio</artifactId>
5555
<version>1.3.7</version>
5656
</dependency>
57-
57+
5858
<dependency>
5959
<groupId>io.avaje</groupId>
6060
<artifactId>junit</artifactId>

Diff for: tests/test-nima/pom.xml

+4-24
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,17 @@
3131
<dependency>
3232
<groupId>io.helidon.webserver</groupId>
3333
<artifactId>helidon-webserver</artifactId>
34-
<version>${nima.version}</version>
34+
<version>${helidon.version}</version>
3535
</dependency>
3636
<dependency>
3737
<groupId>io.helidon.webserver</groupId>
3838
<artifactId>helidon-webserver-security</artifactId>
39-
<version>${nima.version}</version>
39+
<version>${helidon.version}</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>io.helidon.http.media</groupId>
4343
<artifactId>helidon-http-media-jsonb</artifactId>
44-
<version>${nima.version}</version>
45-
</dependency>
46-
<dependency>
47-
<groupId>io.avaje</groupId>
48-
<artifactId>avaje-http-helidon-generator</artifactId>
49-
<version>${project.version}</version>
50-
<scope>test</scope>
44+
<version>${helidon.version}</version>
5145
</dependency>
5246
</dependencies>
5347

@@ -58,7 +52,6 @@
5852
<artifactId>maven-compiler-plugin</artifactId>
5953
<version>3.14.0</version>
6054
<configuration>
61-
<release>21</release>
6255
<annotationProcessorPaths>
6356
<path>
6457
<groupId>io.avaje</groupId>
@@ -71,22 +64,9 @@
7164
<version>${avaje-inject.version}</version>
7265
</path>
7366
</annotationProcessorPaths>
74-
<source>21</source>
75-
<target>21</target>
7667
</configuration>
7768
</plugin>
78-
<plugin>
79-
<groupId>io.repaint.maven</groupId>
80-
<artifactId>tiles-maven-plugin</artifactId>
81-
<version>2.40</version>
82-
<extensions>true</extensions>
83-
<configuration>
84-
<tiles>
85-
<tile>org.avaje.tile:lib-classpath:1.1</tile>
86-
</tiles>
87-
</configuration>
88-
</plugin>
89-
<!-- generated by avaje inject -->
69+
9070
<plugin>
9171
<groupId>io.avaje</groupId>
9272
<artifactId>avaje-inject-maven-plugin</artifactId>

Diff for: tests/test-nima/src/main/java/org/example/HelloController.java

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.example;
22

3+
import io.avaje.http.api.BeanParam;
34
import io.avaje.http.api.Controller;
45
import io.avaje.http.api.Default;
56
import io.avaje.http.api.Get;
@@ -27,4 +28,9 @@ Person person(String name, String sortBy) {
2728
String name(String name, String sortBy, @Default("0") long max) {
2829
return "hi " + name;
2930
}
31+
32+
@Get("banana")
33+
Person getP(@BeanParam Person person) {
34+
return person;
35+
}
3036
}

0 commit comments

Comments
 (0)