Skip to content
Draft
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 @@ -12,6 +12,10 @@ import com.google.gson.stream.JsonWriter;
{{#isUri}}
import java.net.URI;
{{/isUri}}
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
Expand Down Expand Up @@ -39,8 +43,16 @@ import java.net.URI;
{{{name}}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}

private static final Map<{{{dataType}}}, {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive enum lookup lowercases the input but the BY_VALUE map is populated with original casing, so mixed-case enum values will not be found when useEnumCaseInsensitive is enabled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/native/modelEnum.mustache, line 52:

<comment>Case-insensitive enum lookup lowercases the input but the BY_VALUE map is populated with original casing, so mixed-case enum values will not be found when useEnumCaseInsensitive is enabled.</comment>

<file context>
@@ -39,8 +43,16 @@ import java.net.URI;
 
+  static {
+    for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
+      BY_VALUE.put(e.value, e);
+    }
+  }
</file context>
Suggested change
BY_VALUE.put(e.value, e);
BY_VALUE.put({{#useEnumCaseInsensitive}}e.value.toLowerCase(Locale.ROOT){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}e.value{{/useEnumCaseInsensitive}}, e);
Fix with Cubic

}
}

{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -61,12 +73,7 @@ import java.net.URI;
@JsonCreator
{{/jackson}}
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
return b;
}
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
}
{{#supportUrlQuery}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import java.io.IOException;
{{#isUri}}
import java.net.URI;
{{/isUri}}
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import com.google.gson.TypeAdapter;
import com.google.gson.JsonElement;
import com.google.gson.annotations.JsonAdapter;
Expand All @@ -28,8 +32,16 @@ import com.google.gson.stream.JsonWriter;
{{{name}}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}

private static final Map<{{{dataType}}}, {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive lookup lowercases the input but the BY_VALUE map is populated with unnormalized keys, so enums with uppercase values will not be found.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/modelEnum.mustache, line 41:

<comment>Case-insensitive lookup lowercases the input but the BY_VALUE map is populated with unnormalized keys, so enums with uppercase values will not be found.</comment>

<file context>
@@ -28,8 +32,16 @@ import com.google.gson.stream.JsonWriter;
 
+  static {
+    for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
+      BY_VALUE.put(e.value, e);
+    }
+  }
</file context>
Fix with Cubic

}
}

{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -44,12 +56,7 @@ import com.google.gson.stream.JsonWriter;
}

public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
return b;
}
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: useEnumCaseInsensitive applies to all enums, but this template always calls value.toLowerCase(...) without checking isString, causing compilation errors for non-String enum value types.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/modelEnum.mustache, line 59:

<comment>useEnumCaseInsensitive applies to all enums, but this template always calls value.toLowerCase(...) without checking isString, causing compilation errors for non-String enum value types.</comment>

<file context>
@@ -44,12 +56,7 @@ import com.google.gson.stream.JsonWriter;
-      }
-    }
-    {{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
+    return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
   }
 
</file context>
Suggested change
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
return Optional.ofNullable({{#useEnumCaseInsensitive}}{{#isString}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/isString}}{{^isString}}BY_VALUE.get(value){{/isString}}{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
Fix with Cubic

}

public static class Adapter extends TypeAdapter<{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import com.google.gson.stream.JsonWriter;
{{#isUri}}
import java.net.URI;
{{/isUri}}
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
Expand Down Expand Up @@ -39,8 +43,16 @@ import java.net.URI;
{{{name}}}({{{value}}}){{^-last}},
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}

private static final Map<{{{dataType}}}, {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive lookup lowercases the input but the BY_VALUE map is populated with unnormalized keys, so enums with uppercase/mixed-case values will no longer resolve.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/modelEnum.mustache, line 52:

<comment>Case-insensitive lookup lowercases the input but the BY_VALUE map is populated with unnormalized keys, so enums with uppercase/mixed-case values will no longer resolve.</comment>

<file context>
@@ -39,8 +43,16 @@ import java.net.URI;
 
+  static {
+    for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
+      BY_VALUE.put(e.value, e);
+    }
+  }
</file context>
Suggested change
BY_VALUE.put(e.value, e);
BY_VALUE.put({{#useEnumCaseInsensitive}}e.value.toLowerCase(Locale.ROOT){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}e.value{{/useEnumCaseInsensitive}}, e);
Fix with Cubic

}
}

{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -61,12 +73,7 @@ import java.net.URI;
@JsonCreator
{{/jackson}}
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
return b;
}
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}return {{{name}}};{{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/enumUnknownDefaultCase}}{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
}
{{#gson}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive lookup lowercases the input but BY_VALUE is populated with original-cased keys, so valid enum values with uppercase characters will not resolve when useEnumCaseInsensitive is enabled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaJaxRS/modelEnum.mustache, line 58:

<comment>Case-insensitive lookup lowercases the input but BY_VALUE is populated with original-cased keys, so valid enum values with uppercase characters will not resolve when useEnumCaseInsensitive is enabled.</comment>

<file context>
@@ -43,12 +55,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
-      }
-    }
-    {{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
+    return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
   }
 {{/jackson}}
</file context>
Fix with Cubic

import com.fasterxml.jackson.annotation.JsonValue;
{{/jackson}}
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
Expand All @@ -22,8 +26,16 @@ import com.fasterxml.jackson.annotation.JsonValue;
{{/-last}}{{#-last}};{{/-last}}{{/enumVars}}{{/allowableValues}}
{{/gson}}

private static final Map<{{{dataType}}}, {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
}
}

{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -43,12 +55,7 @@ import com.fasterxml.jackson.annotation.JsonValue;

@JsonCreator
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
return b;
}
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: useEnumCaseInsensitive now calls toLowerCase on any enum value type, which breaks compilation for non-String enums when the flag is enabled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/JavaJaxRS/modelEnum.mustache, line 58:

<comment>`useEnumCaseInsensitive` now calls `toLowerCase` on any enum value type, which breaks compilation for non-String enums when the flag is enabled.</comment>

<file context>
@@ -43,12 +55,7 @@ import com.fasterxml.jackson.annotation.JsonValue;
-      }
-    }
-    {{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
+    return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
   }
 {{/jackson}}
</file context>
Suggested change
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
return Optional.ofNullable({{#useEnumCaseInsensitive}}{{#isString}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/isString}}{{^isString}}BY_VALUE.get(value){{/isString}}{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
Fix with Cubic

}
{{/jackson}}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* {{description}}{{^description}}Gets or Sets {{{name}}}{{/description}}
*/
Expand Down Expand Up @@ -28,8 +33,16 @@
{{/enumVars}}
{{/allowableValues}}

private static final Map<{{{dataType}}}, {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive lookup lowercases the input, but BY_VALUE is populated with original values, so mixed/upper-case enum values won't be found when useEnumCaseInsensitive is enabled.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/java-helidon/server/libraries/mp/modelEnum.mustache, line 42:

<comment>Case-insensitive lookup lowercases the input, but BY_VALUE is populated with original values, so mixed/upper-case enum values won't be found when useEnumCaseInsensitive is enabled.</comment>

<file context>
@@ -28,8 +33,16 @@
 
+    static {
+      for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}} e: values()) {
+        BY_VALUE.put(e.value, e);
+      }
+    }
</file context>
Fix with Cubic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it does not respect the case. This only works for exact equals.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, I don't think it will be possible, at least not with some workaround. What if EXAMPLE_1("Example") and EXAMPLE_2("example") exists, there will be a key conflict when populating the Map after making the value lowercase...

}
}

{{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -46,12 +59,7 @@

{{#jackson}}@JsonCreator{{/jackson}}
public static {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{{datatypeWithEnum}}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.equals(value)) {
return b;
}
}
{{#isNullable}}return null;{{/isNullable}}{{^isNullable}}throw new IllegalArgumentException("Unexpected value '" + value + "'");{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)), when it's already in an Optional-stream?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the value is non-String, and the flag useEnumCaseInsensitive is true?

}
{{#jsonb}}
public static final class Deserializer implements JsonbDeserializer<{{datatypeWithEnum}}> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
{{/jackson}}
{{#useEnumCaseInsensitive}}import java.util.Locale;
{{/useEnumCaseInsensitive}}import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
* {{^description}}Gets or Sets {{{name}}}{{/description}}{{#description}}{{description}}{{/description}}
Expand All @@ -27,8 +31,16 @@ import com.fasterxml.jackson.annotation.JsonValue;
{{/enumVars}}
{{/allowableValues}}

private static final Map<{{{dataType}}}, {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}> BY_VALUE = new HashMap<>();

private {{{dataType}}} value;

static {
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
BY_VALUE.put(e.value, e);
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Case-insensitive deserialization lowercases the input but the BY_VALUE map is populated with original casing, so mixed-case enum values won't resolve.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/java-micronaut/common/model/modelEnum.mustache, line 40:

<comment>Case-insensitive deserialization lowercases the input but the BY_VALUE map is populated with original casing, so mixed-case enum values won't resolve.</comment>

<file context>
@@ -27,8 +31,16 @@ import com.fasterxml.jackson.annotation.JsonValue;
 
+    static {
+        for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} e: values()) {
+            BY_VALUE.put(e.value, e);
+        }
+    }
</file context>
Fix with Cubic

}
}

{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}({{{dataType}}} value) {
this.value = value;
}
Expand All @@ -49,16 +61,6 @@ import com.fasterxml.jackson.annotation.JsonValue;
@JsonCreator
{{/jackson}}
public static {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} fromValue({{{dataType}}} value) {
for ({{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}} b : {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{{classname}}}{{/datatypeWithEnum}}.values()) {
if (b.value.{{^isString}}equals{{/isString}}{{#isString}}{{#useEnumCaseInsensitive}}equalsIgnoreCase{{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}equals{{/useEnumCaseInsensitive}}{{/isString}}(value)) {
return b;
}
}
{{#isNullable}}
return null;
{{/isNullable}}
{{^isNullable}}
throw new IllegalArgumentException("Unexpected value '" + value + "'");
{{/isNullable}}
return Optional.ofNullable({{#useEnumCaseInsensitive}}value == null ? null : BY_VALUE.get(value.toLowerCase(Locale.ROOT)){{/useEnumCaseInsensitive}}{{^useEnumCaseInsensitive}}BY_VALUE.get(value){{/useEnumCaseInsensitive}}).{{#isNullable}}orElse(null){{/isNullable}}{{^isNullable}}{{#enumUnknownDefaultCase}}{{#allowableValues}}{{#enumVars}}{{#-last}}orElse({{{name}}}){{/-last}}{{/enumVars}}{{/allowableValues}}{{/enumUnknownDefaultCase}}{{^enumUnknownDefaultCase}}orElseThrow(() -> new IllegalArgumentException("Unexpected value '" + value + "'")){{/enumUnknownDefaultCase}}{{/isNullable}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openapitools.codegen.CodegenConstants.*;
import static org.openapitools.codegen.TestUtils.*;
import static org.openapitools.codegen.languages.AbstractJavaCodegen.DISABLE_DISCRIMINATOR_JSON_IGNORE_PROPERTIES;
import static org.openapitools.codegen.languages.AbstractJavaCodegen.OPENAPI_NULLABLE;
import static org.openapitools.codegen.languages.AbstractJavaCodegen.USE_ONE_OF_INTERFACES;
import static org.openapitools.codegen.languages.JavaClientCodegen.*;
import static org.testng.Assert.*;

Expand Down Expand Up @@ -2373,9 +2376,9 @@ public void testEnumCaseInsensitive_issue8084() {
Map<String, File> files = new DefaultGenerator().opts(new ClientOptInput().openAPI(openAPI).config(codegen))
.generate().stream().collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("EnumTest.java"))
.assertMethod("fromValue")
.bodyContainsLines("if (b.value.equalsIgnoreCase(value)) {");
assertThat(files.get("EnumTest.java"))
.content()
.contains("toLowerCase(Locale.ROOT)");
}

@Test
Expand All @@ -2389,9 +2392,9 @@ public void testEnumCaseSensitive_issue8084() {
Map<String, File> files = new DefaultGenerator().opts(new ClientOptInput().openAPI(openAPI).config(codegen))
.generate().stream().collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("EnumTest.java"))
.assertMethod("fromValue")
.bodyContainsLines("if (b.value.equals(value)) {");
assertThat(files.get("EnumTest.java"))
.content()
.contains("new HashMap<>()");
}

@Test
Expand Down
59 changes: 59 additions & 0 deletions perf/jmh/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.openapitools</groupId>
<artifactId>enum-lookup-jmh</artifactId>
<name>Enum Lookup JMH</name>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>benchmarks</finalName>
<transformers>
<transformer>
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.37</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<jmh.version>1.37</jmh.version>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Loading