Skip to content

Commit 1bf2ee7

Browse files
authored
Merge pull request #399 from SentryMan/nested
[helidon-generato] Fix Nested Types in other packages
2 parents 225745d + d0c5fd2 commit 1bf2ee7

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

http-generator-core/src/main/java/io/avaje/http/generator/core/UType.java

+23-23
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,28 @@ default String genericParams() {
7575
return "";
7676
}
7777

78+
static String innerTypesImport(String type) {
79+
final var parts = type.split("\\.");
80+
var result = "";
81+
var foundUpper = false;
82+
83+
for (var i = 0; i < parts.length; i++) {
84+
if (!Character.isUpperCase(parts[i].charAt(0))) {
85+
result += parts[i] + ".";
86+
} else if (!foundUpper) {
87+
foundUpper = true;
88+
result += parts[i] + (i == parts.length - 1 ? "" : ".");
89+
} else {
90+
break;
91+
}
92+
}
93+
94+
if (result.endsWith(".")) {
95+
result = result.substring(0, result.length() - 1);
96+
}
97+
return result;
98+
}
99+
78100
class VoidType implements UType {
79101

80102
@Override
@@ -122,7 +144,7 @@ public String full() {
122144
public Set<String> importTypes() {
123145
return isJavaLangPackage(rawType)
124146
? Set.of()
125-
: Collections.singleton(rawType.replace("[]", ""));
147+
: Collections.singleton(innerTypesImport(rawType.replace("[]", "")));
126148
}
127149

128150
@Override
@@ -217,28 +239,6 @@ public Set<String> importTypes() {
217239
return set;
218240
}
219241

220-
public String innerTypesImport(String type) {
221-
final var parts = type.split("\\.");
222-
var result = "";
223-
var foundUpper = false;
224-
225-
for (var i = 0; i < parts.length; i++) {
226-
if (!Character.isUpperCase(parts[i].charAt(0))) {
227-
result += parts[i] + ".";
228-
} else if (!foundUpper) {
229-
foundUpper = true;
230-
result += parts[i] + (i == parts.length - 1 ? "" : ".");
231-
} else {
232-
break;
233-
}
234-
}
235-
236-
if (result.endsWith(".")) {
237-
result = result.substring(0, result.length() - 1);
238-
}
239-
return result;
240-
}
241-
242242
@Override
243243
public boolean isGeneric() {
244244
return true;

tests/test-nima-jsonb/src/main/java/org/example/path/PathTestController.java

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

3+
import org.example.path.nest.PathNestController.NestedTypeResponse;
4+
35
import io.avaje.http.api.Controller;
46
import io.avaje.http.api.Get;
57
import io.avaje.http.api.Path;
@@ -14,4 +16,9 @@ public class PathTestController {
1416
String hello() {
1517
return "hi";
1618
}
19+
20+
@Get("/nested/respo")
21+
NestedTypeResponse nested() {
22+
return new NestedTypeResponse(0, null);
23+
}
1724
}

tests/test-nima-jsonb/src/main/java/org/example/path/nest/PathNestController.java

+3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
import io.avaje.http.api.Get;
55
import io.avaje.http.api.Path;
66
import io.avaje.http.api.Produces;
7+
import io.avaje.jsonb.Json;
78

89
@Path("test")
910
@Controller
1011
public class PathNestController {
12+
@Json
13+
public record NestedTypeResponse(long id, String name) {}
1114

1215
@Produces("text/plain")
1316
@Get

0 commit comments

Comments
 (0)