Skip to content

[helidon] Bug fix for list of query parameters or form parameters when parameters is empty #610

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
Jun 2, 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 @@ -118,8 +118,8 @@ public void writeReadMapParameter(Append writer, ParamType paramType) {
@Override
public void writeReadCollectionParameter(Append writer, ParamType paramType, String paramName) {
switch (paramType) {
case QUERYPARAM -> writer.append("queryParams.all(\"%s\")", paramName);
case FORMPARAM -> writer.append("formParams.all(\"%s\")", paramName);
case QUERYPARAM -> writer.append("queryParams.all(\"%s\", () -> java.util.List.of())", paramName);
case FORMPARAM -> writer.append("formParams.all(\"%s\", () -> java.util.List.of())", paramName);

case HEADER -> writer.append(
"req.headers().all(\"%s\", () -> java.util.List.of())", paramName);
Expand Down
6 changes: 6 additions & 0 deletions tests/test-nima/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
<artifactId>avaje-http-helidon-generator</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.avaje</groupId>
<artifactId>avaje-http-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import io.avaje.http.api.Get;
import io.avaje.http.api.Produces;

import java.util.List;

@Controller
public class HelloController {

Expand Down Expand Up @@ -33,4 +35,10 @@ String name(String name, String sortBy, @Default("0") long max) {
Person getP(@BeanParam Person person) {
return person;
}

@Produces("text/plain")
@Get("listParams")
String listParam(List<String> codes) {
return "codes:" + codes;
}
}
47 changes: 47 additions & 0 deletions tests/test-nima/src/test/java/org/example/BaseWebTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.example;

import io.avaje.http.client.HttpClient;
import io.avaje.inject.BeanScope;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.http.HttpFeature;
import io.helidon.webserver.http.HttpRouting;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

import java.time.Duration;
import java.util.List;

public class BaseWebTest {

static WebServer webServer;

public static String baseUrl;


@BeforeAll
public static void init() {
List<HttpFeature> routes = BeanScope.builder().build().list(HttpFeature.class);
final var builder = HttpRouting.builder();
routes.forEach(builder::addFeature);

webServer = WebServer.builder().addRouting(builder)
.port(9067)
.build()
.start();

baseUrl = "http://localhost:9067";
}

@AfterAll
public static void shutdown() {
webServer.stop();
}

public static HttpClient client() {
return HttpClient.builder()
.baseUrl(baseUrl)
.requestTimeout(Duration.ofMinutes(2))
//.bodyAdapter(new JacksonBodyAdapter())
.build();
}
}
46 changes: 46 additions & 0 deletions tests/test-nima/src/test/java/org/example/HelloControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.example;

import org.junit.jupiter.api.Test;
import java.net.http.HttpResponse;


import static org.assertj.core.api.Assertions.assertThat;

class HelloControllerTest extends BaseWebTest {

@Test
void listParamOne() {
HttpResponse<String> res = client().request()
.path("listParams")
.queryParam("codes", "123")
.GET()
.asPlainString();

assertThat(res.statusCode()).isEqualTo(200);
assertThat(res.body()).isEqualTo("codes:[123]");
}

@Test
void listParamMultiple() {
HttpResponse<String> res = client().request()
.path("listParams")
.queryParam("codes", "123")
.queryParam("codes", "456")
.GET()
.asPlainString();

assertThat(res.statusCode()).isEqualTo(200);
assertThat(res.body()).isEqualTo("codes:[123, 456]");
}

@Test
void listParamEmpty() {
HttpResponse<String> res = client().request()
.path("listParams")
.GET()
.asPlainString();

assertThat(res.statusCode()).isEqualTo(200);
assertThat(res.body()).isEqualTo("codes:[]");
}
}