File tree Expand file tree Collapse file tree 6 files changed +72
-2
lines changed
main/java/io/avaje/http/generator/core
test/java/io/avaje/http/generator/core
tests/test-javalin-jsonb/src/main
java/org/example/myapp/web Expand file tree Collapse file tree 6 files changed +72
-2
lines changed Original file line number Diff line number Diff line change @@ -316,12 +316,12 @@ static class EnumHandler extends ObjectHandler {
316316
317317 @ Override
318318 public String toMethod () {
319- return "(" + type .shortType () + ") toEnum(" + type .shortType () + ".class, " ;
319+ return "(" + type .shortTypeNested () + ") toEnum(" + type .shortTypeNested () + ".class, " ;
320320 }
321321
322322 @ Override
323323 public String asMethod () {
324- return "(" + type .shortType () + ") asEnum(" + type .shortType () + ".class, " ;
324+ return "(" + type .shortTypeNested () + ") asEnum(" + type .shortTypeNested () + ".class, " ;
325325 }
326326 }
327327
Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ static UType parse(String type) {
3131 */
3232 String shortType ();
3333
34+ /**
35+ * Return the short type taking nested type into account.
36+ */
37+ default String shortTypeNested () {
38+ return shortType ();
39+ }
40+
3441 /**
3542 * Return the short name.
3643 */
@@ -152,6 +159,11 @@ public String shortType() {
152159 return Util .shortName (rawType );
153160 }
154161
162+ @ Override
163+ public String shortTypeNested () {
164+ return Util .shortName (rawType , true );
165+ }
166+
155167 @ Override
156168 public String shortName () {
157169 return Util .initLower (shortType ()).replace ("." , "$" );
Original file line number Diff line number Diff line change 22
33import org .junit .jupiter .api .Test ;
44
5+ import static org .assertj .core .api .Assertions .assertThat ;
56import static org .junit .jupiter .api .Assertions .*;
67
78class UTypeTest {
@@ -17,4 +18,12 @@ void isJavaLangPackage_expect_false() {
1718 assertFalse (UType .isJavaLangPackage ("java.lang.other.Foo" ));
1819 assertFalse (UType .isJavaLangPackage ("not.lang.Foo" ));
1920 }
21+
22+ @ Test
23+ void parseNestedEnum () {
24+ UType uType = UType .parse ("my.pack.Foo.NestedEnum" );
25+ assertThat (uType .mainType ()).isEqualTo ("my.pack.Foo.NestedEnum" );
26+ assertThat (uType .shortType ()).isEqualTo ("Foo.NestedEnum" );
27+ assertThat (uType .shortTypeNested ()).isEqualTo ("NestedEnum" );
28+ }
2029}
Original file line number Diff line number Diff line change 2525import io .javalin .http .Context ;
2626import io .swagger .v3 .oas .annotations .Hidden ;
2727import jakarta .inject .Inject ;
28+ import org .example .myapp .web .other .Foo ;
2829
2930/**
3031 * Hello resource manager.
@@ -183,4 +184,10 @@ String controlStatusCode(Context ctx) {
183184 ctx .status (201 );
184185 return "controlStatusCode" ;
185186 }
187+
188+ @ Produces (value = "text/plain" )
189+ @ Get ("takesNestedEnum" )
190+ String takesNestedEnum (Foo .NestedEnum myEnum ) {
191+ return "takesNestedEnum-" + myEnum ;
192+ }
186193}
Original file line number Diff line number Diff line change 1+ package org .example .myapp .web .other ;
2+
3+ public class Foo {
4+ public enum NestedEnum {
5+ A , B , C
6+ }
7+ }
Original file line number Diff line number Diff line change 646646 }
647647 }
648648 },
649+ "/hello/takesNestedEnum" : {
650+ "get" : {
651+ "tags" : [
652+
653+ ],
654+ "summary" : " " ,
655+ "description" : " " ,
656+ "parameters" : [
657+ {
658+ "name" : " myEnum" ,
659+ "in" : " query" ,
660+ "schema" : {
661+ "type" : " string" ,
662+ "enum" : [
663+ " A" ,
664+ " B" ,
665+ " C"
666+ ]
667+ }
668+ }
669+ ],
670+ "responses" : {
671+ "200" : {
672+ "description" : " " ,
673+ "content" : {
674+ "text/plain" : {
675+ "schema" : {
676+ "type" : " string"
677+ }
678+ }
679+ }
680+ }
681+ }
682+ }
683+ },
649684 "/hello/withMatrix/{year_segment}/{other}" : {
650685 "get" : {
651686 "tags" : [
You can’t perform that action at this time.
0 commit comments