File tree Expand file tree Collapse file tree
modules/openapi-generator/src
main/java/org/openapitools/codegen/languages
test/java/org/openapitools/codegen/scala Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -624,11 +624,24 @@ public String toDefaultValue(Schema p) {
624624 }
625625 }
626626
627+ @ Override
628+ public String toEnumVarName (String value , String datatype ) {
629+ String sanitized = sanitizeName (value );
630+
631+ // Preserve SCREAMING_SNAKE_CASE values
632+ if (sanitized .matches ("^[A-Z][A-Z0-9_]*$" )
633+ && !isReservedWord (sanitized )) {
634+ return sanitized ;
635+ }
636+
637+ return super .formatIdentifier (sanitized , true );
638+
639+ }
627640
628641 private class EnumEntryLambda extends CustomLambda {
629642 @ Override
630643 public String formatFragment (String fragment ) {
631- return formatIdentifier (fragment , true );
644+ return toEnumVarName (fragment , "string" );
632645 }
633646 }
634647
Original file line number Diff line number Diff line change @@ -144,6 +144,42 @@ public void convertVarNameCamelCase() {
144144 assertEquals (codegen .toVarName ("1AAaa" ), "`1aAaa`" );
145145 }
146146
147+ @ Test
148+ public void preserveScreamingSnakeCaseEnumNames () {
149+ ScalaHttp4sClientCodegen codegen = new ScalaHttp4sClientCodegen ();
150+
151+ assertEquals (
152+ codegen .toEnumVarName ("ACTIVE_STATUS" , "string" ),
153+ "ACTIVE_STATUS"
154+ );
155+
156+ assertEquals (
157+ codegen .toEnumVarName ("INACTIVE_STATUS" , "string" ),
158+ "INACTIVE_STATUS"
159+ );
160+
161+ assertEquals (
162+ codegen .toEnumVarName ("USER_123_STATUS" , "string" ),
163+ "USER_123_STATUS"
164+ );
165+ }
166+
167+ @ Test
168+ public void formatRegularEnumNames () {
169+ ScalaHttp4sClientCodegen codegen = new ScalaHttp4sClientCodegen ();
170+
171+ assertEquals (
172+ codegen .toEnumVarName ("available" , "string" ),
173+ "Available"
174+ );
175+
176+ assertEquals (
177+ codegen .toEnumVarName ("pending_status" , "string" ),
178+ "PendingStatus"
179+ );
180+
181+ }
182+
147183 @ Test
148184 public void encodePath () {
149185 ScalaHttp4sClientCodegen codegen = new ScalaHttp4sClientCodegen ();
You can’t perform that action at this time.
0 commit comments