Skip to content

Improve the compile error message when we think @BeanParam is needed #582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static io.avaje.http.generator.core.ProcessingContext.platform;
import static io.avaje.http.generator.core.ProcessingContext.superMethods;

import java.text.MessageFormat;
import java.util.*;
import java.util.function.Consumer;
import java.util.function.Function;
Expand Down Expand Up @@ -343,18 +344,23 @@ void read() {
final MethodParam param = new MethodParam(p, type, rawType, defaultParamType, formMarker);
params.add(param);

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

param.addImports(bean);
}
}

private static boolean isBodyParam(MethodParam param) {
return param.isBody()
&& !"java.util.Map".equals(param.utype().mainType())
&& !"ClientPlatformAdapter"
.equals(ProcessingContext.platform().getClass().getSimpleName());
}

public void buildApiDoc() {
buildApiDocumentation();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ private boolean usesFormParams() {
}

private boolean usesQueryParams() {
return method.params().stream().anyMatch(p -> ParamType.QUERYPARAM.equals(p.paramType()));
return method.params().stream().anyMatch(p ->
ParamType.QUERYPARAM.equals(p.paramType())
|| ParamType.BEANPARAM.equals(p.paramType()));
}

private void writeContextReturn(String indent) {
Expand Down
2 changes: 1 addition & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<jackson.version>2.18.3</jackson.version>
<jex.version>3.0-RC22</jex.version>
<avaje-inject.version>11.3</avaje-inject.version>
<nima.version>4.2.0</nima.version>
<helidon.version>4.2.0</helidon.version>
<javalin.version>6.5.0</javalin.version>
</properties>

Expand Down
6 changes: 3 additions & 3 deletions tests/test-nima-jsonb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>${nima.version}</version>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonb</artifactId>
<version>${nima.version}</version>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.avaje</groupId>
Expand All @@ -54,7 +54,7 @@
<artifactId>jstachio</artifactId>
<version>1.3.7</version>
</dependency>

<dependency>
<groupId>io.avaje</groupId>
<artifactId>junit</artifactId>
Expand Down
28 changes: 4 additions & 24 deletions tests/test-nima/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,17 @@
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>${nima.version}</version>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver-security</artifactId>
<version>${nima.version}</version>
<version>${helidon.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonb</artifactId>
<version>${nima.version}</version>
</dependency>
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-helidon-generator</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<version>${helidon.version}</version>
</dependency>
</dependencies>

Expand All @@ -58,7 +52,6 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<release>21</release>
<annotationProcessorPaths>
<path>
<groupId>io.avaje</groupId>
Expand All @@ -71,22 +64,9 @@
<version>${avaje-inject.version}</version>
</path>
</annotationProcessorPaths>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>io.repaint.maven</groupId>
<artifactId>tiles-maven-plugin</artifactId>
<version>2.40</version>
<extensions>true</extensions>
<configuration>
<tiles>
<tile>org.avaje.tile:lib-classpath:1.1</tile>
</tiles>
</configuration>
</plugin>
<!-- generated by avaje inject -->

<plugin>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example;

import io.avaje.http.api.BeanParam;
import io.avaje.http.api.Controller;
import io.avaje.http.api.Default;
import io.avaje.http.api.Get;
Expand Down Expand Up @@ -27,4 +28,9 @@ Person person(String name, String sortBy) {
String name(String name, String sortBy, @Default("0") long max) {
return "hi " + name;
}

@Get("banana")
Person getP(@BeanParam Person person) {
return person;
}
}