Skip to content

Fix Query Param Collection Imports #186

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 17, 2023
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
2 changes: 1 addition & 1 deletion http-generator-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<artifactId>avaje-http-generator-core</artifactId>

<properties>
<avaje.prisms.version>1.6</avaje.prisms.version>
<avaje.prisms.version>1.8</avaje.prisms.version>
</properties>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import static io.avaje.http.generator.core.ProcessingContext.platform;
import static io.avaje.http.generator.core.ProcessingContext.typeElement;

import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
Expand Down Expand Up @@ -38,6 +39,7 @@ public class ElementReader {
private boolean notNullKotlin;
private boolean isParamCollection;
private boolean isParamMap;
private final Set<String> imports = new HashSet<>();
// private boolean notNullJavax;

ElementReader(Element element, ParamType defaultType, boolean formMarker) {
Expand All @@ -59,6 +61,11 @@ public class ElementReader {

typeHandler = initTypeHandler();

this.imports.add(rawType);
if (typeHandler != null) {
this.imports.addAll(typeHandler.importTypes());
}

this.formMarker = formMarker;
this.varName = element.getSimpleName().toString();
this.snakeName = Util.snakeCase(varName);
Expand Down Expand Up @@ -226,12 +233,8 @@ private String handlerShortType() {
}

void addImports(ControllerReader bean) {
if (typeHandler != null) {
typeHandler.importTypes().stream().filter(Objects::nonNull).forEach(bean::addImportType);

} else {
bean.addImportType(rawType);
}
bean.addImportTypes(imports);
}

void writeParamName(Append writer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
import org.example.myapp.web.AppRoles;
import org.example.myapp.web.HelloDto;
import org.example.myapp.web.Roles;
import org.example.myapp.web.ServerType;

import io.avaje.http.api.Controller;
import io.avaje.http.api.Default;
import io.avaje.http.api.Form;
import io.avaje.http.api.Get;
import io.avaje.http.api.Header;
Expand All @@ -19,6 +21,7 @@
import io.avaje.http.api.Post;
import io.avaje.http.api.Produces;
import io.avaje.http.api.Put;
import io.avaje.http.api.QueryParam;
import io.javalin.http.Context;

@Path("test/")
Expand Down Expand Up @@ -129,4 +132,9 @@ void neo(
CompletableFuture<HelloDto> getAllAsync() {
return CompletableFuture.supplyAsync(() -> new HelloDto(12, "Jim", "asd"));
}

@Get("/enumQuery2")
String enumMultiQuery(@QueryParam @Default({"FFA", "PROXY"}) Set<ServerType> type) {
return type.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.example.myapp.web.ServerType;

Expand Down Expand Up @@ -36,11 +35,6 @@ String enumQuery(@QueryParam @Default("FFA") ServerType type) {
return type.name();
}

@Get("/enumQuery2")
String enumMultiQuery(@QueryParam @Default({"FFA", "PROXY"}) Set<ServerType> type) {
return type.toString();
}

@Post("/enumQueryImplied")
String enumQueryImplied(String s, @QueryParam ServerType type) {
return type.name();
Expand Down