Skip to content

[helidon-generator] Fix Nested Types in other packages #399

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 1 commit into from
Mar 10, 2024
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 @@ -75,6 +75,28 @@ default String genericParams() {
return "";
}

static String innerTypesImport(String type) {
final var parts = type.split("\\.");
var result = "";
var foundUpper = false;

for (var i = 0; i < parts.length; i++) {
if (!Character.isUpperCase(parts[i].charAt(0))) {
result += parts[i] + ".";
} else if (!foundUpper) {
foundUpper = true;
result += parts[i] + (i == parts.length - 1 ? "" : ".");
} else {
break;
}
}

if (result.endsWith(".")) {
result = result.substring(0, result.length() - 1);
}
return result;
}

class VoidType implements UType {

@Override
Expand Down Expand Up @@ -122,7 +144,7 @@ public String full() {
public Set<String> importTypes() {
return isJavaLangPackage(rawType)
? Set.of()
: Collections.singleton(rawType.replace("[]", ""));
: Collections.singleton(innerTypesImport(rawType.replace("[]", "")));
}

@Override
Expand Down Expand Up @@ -217,28 +239,6 @@ public Set<String> importTypes() {
return set;
}

public String innerTypesImport(String type) {
final var parts = type.split("\\.");
var result = "";
var foundUpper = false;

for (var i = 0; i < parts.length; i++) {
if (!Character.isUpperCase(parts[i].charAt(0))) {
result += parts[i] + ".";
} else if (!foundUpper) {
foundUpper = true;
result += parts[i] + (i == parts.length - 1 ? "" : ".");
} else {
break;
}
}

if (result.endsWith(".")) {
result = result.substring(0, result.length() - 1);
}
return result;
}

@Override
public boolean isGeneric() {
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.example.path;

import org.example.path.nest.PathNestController.NestedTypeResponse;

import io.avaje.http.api.Controller;
import io.avaje.http.api.Get;
import io.avaje.http.api.Path;
Expand All @@ -14,4 +16,9 @@ public class PathTestController {
String hello() {
return "hi";
}

@Get("/nested/respo")
NestedTypeResponse nested() {
return new NestedTypeResponse(0, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
import io.avaje.http.api.Get;
import io.avaje.http.api.Path;
import io.avaje.http.api.Produces;
import io.avaje.jsonb.Json;

@Path("test")
@Controller
public class PathNestController {
@Json
public record NestedTypeResponse(long id, String name) {}

@Produces("text/plain")
@Get
Expand Down