Skip to content

[Java] Add USE_ENUM_CASE_INSENSITIVE for java client generator#24180

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
hamburml:feature/AddEnumCaseInsensitiveJavaGen
Jul 2, 2026
Merged

[Java] Add USE_ENUM_CASE_INSENSITIVE for java client generator#24180
wing328 merged 1 commit into
OpenAPITools:masterfrom
hamburml:feature/AddEnumCaseInsensitiveJavaGen

Conversation

@hamburml

@hamburml hamburml commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Add USE_ENUM_CASE_INSENSITIVE for java client generator, also add test

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Adds case-insensitive enum matching to the Java MicroProfile client generator. When useEnumCaseInsensitive is enabled, generated enums accept values regardless of case in fromValue and during jackson deserialization.

  • New Features

    • Added additionalProperties.useEnumCaseInsensitive for the java generator (microprofile library); when enabled, uses equalsIgnoreCase in enumClass.mustache (including the Jackson enum deserializer) and enumOuterClass.mustache.
    • Added bin/configs/java-microprofile-rest-client-3.0-jackson-ignore-case.yaml and a generated sample under samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignore-case to validate equalsIgnoreCase behavior with MicroProfile Rest Client 3.0 and jackson.
  • Migration

    • Enable with --additional-properties useEnumCaseInsensitive=true (or useEnumCaseInsensitive: true in your config).

Written for commit a565f28. Summary will update on new commits.

Review in cubic

@hamburml hamburml force-pushed the feature/AddEnumCaseInsensitiveJavaGen branch from bda1571 to 4f440c9 Compare July 1, 2026 15:07

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

5 issues found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/PetApi.md">

<violation number="1" location="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/PetApi.md:50">
P2: Generated Java example code for void-returning API methods uses invalid syntax `void result = ...`. In Java, `void` cannot be used as a variable type, making these examples uncompilable. This affects `addPet`, `deletePet`, `updatePet`, and `updatePetWithForm` example blocks in the generated documentation.</violation>
</file>

<file name="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/FakeApi.md">

<violation number="1" location="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/FakeApi.md:1013">
P0: Generated example contains invalid Java enum literal syntax: `Arrays.asList(-efg)` is not valid Java. Enum constants must be referenced properly (e.g., `EnumClass.EFG`), and `-efg` will produce a compile error because it parses as unary minus on an undefined variable.</violation>
</file>

<file name="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/pom.xml">

<violation number="1" location="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/pom.xml:4">
P1: Duplicate Maven coordinates detected: the new `ignoreCase` sample POM reuses the same `groupId/artifactId/version` as the existing `microprofile-rest-client-3.0-jackson` sample. This causes local Maven repository collisions and can lead to cross-sample build artifacts overwriting each other in CI.</violation>
</file>

<file name="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/UserApi.md">

<violation number="1" location="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/UserApi.md:108">
P2: Example code for list/array parameters is missing required `java.util.List` and `java.util.Arrays` imports</violation>
</file>

<file name="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/StoreApi.md">

<violation number="1" location="samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/StoreApi.md:62">
P2: Dead documentation link: generated StoreApi.md links to `Void.md`, but `Void.md` does not exist in the generated docs directory or anywhere in the Java samples. Other Java client generators in this repo use `null (empty response body)` for void returns instead.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

String enumQueryString = "_abc"; // String | Query parameter enum test (string)
Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double)
Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P0: Generated example contains invalid Java enum literal syntax: Arrays.asList(-efg) is not valid Java. Enum constants must be referenced properly (e.g., EnumClass.EFG), and -efg will produce a compile error because it parses as unary minus on an undefined variable.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/FakeApi.md, line 1013:

<comment>Generated example contains invalid Java enum literal syntax: `Arrays.asList(-efg)` is not valid Java. Enum constants must be referenced properly (e.g., `EnumClass.EFG`), and `-efg` will produce a compile error because it parses as unary minus on an undefined variable.</comment>

<file context>
@@ -0,0 +1,1555 @@
+        String enumQueryString = "_abc"; // String | Query parameter enum test (string)
+        Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double)
+        Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
+        List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> | 
+        List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
+        String enumFormString = "_abc"; // String | Form parameter enum test (string)
</file context>

<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>microprofile-rest-client-3-jackson</artifactId>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1: Duplicate Maven coordinates detected: the new ignoreCase sample POM reuses the same groupId/artifactId/version as the existing microprofile-rest-client-3.0-jackson sample. This causes local Maven repository collisions and can lead to cross-sample build artifacts overwriting each other in CI.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/pom.xml, line 4:

<comment>Duplicate Maven coordinates detected: the new `ignoreCase` sample POM reuses the same `groupId/artifactId/version` as the existing `microprofile-rest-client-3.0-jackson` sample. This causes local Maven repository collisions and can lead to cross-sample build artifacts overwriting each other in CI.</comment>

<file context>
@@ -0,0 +1,173 @@
+<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>microprofile-rest-client-3-jackson</artifactId>
+  <packaging>jar</packaging>
+  <name>microprofile-rest-client-3-jackson</name>
</file context>

PetApi apiInstance = new PetApi(defaultClient);
Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store
try {
void result = apiInstance.addPet(pet);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Generated Java example code for void-returning API methods uses invalid syntax void result = .... In Java, void cannot be used as a variable type, making these examples uncompilable. This affects addPet, deletePet, updatePet, and updatePetWithForm example blocks in the generated documentation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/PetApi.md, line 50:

<comment>Generated Java example code for void-returning API methods uses invalid syntax `void result = ...`. In Java, `void` cannot be used as a variable type, making these examples uncompilable. This affects `addPet`, `deletePet`, `updatePet`, and `updatePetWithForm` example blocks in the generated documentation.</comment>

<file context>
@@ -0,0 +1,682 @@
+        PetApi apiInstance = new PetApi(defaultClient);
+        Pet pet = new Pet(); // Pet | Pet object that needs to be added to the store
+        try {
+            void result = apiInstance.addPet(pet);
+            System.out.println(result);
+        } catch (ApiException e) {
</file context>

defaultClient.setBasePath("http://petstore.swagger.io:80/v2");

UserApi apiInstance = new UserApi(defaultClient);
List<User> user = Arrays.asList(); // List<User> | List of user object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Example code for list/array parameters is missing required java.util.List and java.util.Arrays imports

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/UserApi.md, line 108:

<comment>Example code for list/array parameters is missing required `java.util.List` and `java.util.Arrays` imports</comment>

<file context>
@@ -0,0 +1,549 @@
+        defaultClient.setBasePath("http://petstore.swagger.io:80/v2");
+
+        UserApi apiInstance = new UserApi(defaultClient);
+        List<User> user = Arrays.asList(); // List<User> | List of user object
+        try {
+            void result = apiInstance.createUsersWithArrayInput(user);
</file context>


### Return type

[**void**](Void.md)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Dead documentation link: generated StoreApi.md links to Void.md, but Void.md does not exist in the generated docs directory or anywhere in the Java samples. Other Java client generators in this repo use null (empty response body) for void returns instead.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignoreCase/docs/StoreApi.md, line 62:

<comment>Dead documentation link: generated StoreApi.md links to `Void.md`, but `Void.md` does not exist in the generated docs directory or anywhere in the Java samples. Other Java client generators in this repo use `null (empty response body)` for void returns instead.</comment>

<file context>
@@ -0,0 +1,283 @@
+
+### Return type
+
+[**void**](Void.md)
+
+### Authorization
</file context>
Suggested change
[**void**](Void.md)
null (empty response body)

@hamburml hamburml force-pushed the feature/AddEnumCaseInsensitiveJavaGen branch from 4f440c9 to 83dbbaa Compare July 1, 2026 15:20
@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor

Could we elaborate a little on the use case for this? Isn't the entire purpose of an enum to be an exact match, and a specification should be able to have "enum: [VALUE, value]" and then that they can mean separate things?

@hamburml

hamburml commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@Mattias-Sehlstedt

The intent is not to change the default enum semantics; exact matching should remain the default. This is only an opt-in compatibility option for APIs that define a canonical enum casing but may return inconsistent casing on the wire, similar to Jackson’s ACCEPT_CASE_INSENSITIVE_ENUMS.

If a spec intentionally defines distinct values like VALUE and value, this option should not be enabled because that would be ambiguous. I can add that caveat to the option documentation.

A lot of other generators (java or jaxrs) already have this config, too. It is simply missing here IMHO.

And sorry, I forgot to push stuff and need to rebuild. Also the documentation is copied from the microprofile-rest-client-3.0-jackson example...

@hamburml hamburml force-pushed the feature/AddEnumCaseInsensitiveJavaGen branch from 83dbbaa to d3cf6ae Compare July 1, 2026 15:57
@Mattias-Sehlstedt

Mattias-Sehlstedt commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

So we are adding it as an alignment between languages and not as something that we have encountered ourselves? I was just wondering if the people that use this setting actually inform the server that they consume that their specification is incorrect. Because turning this on could of course have odd implications somewhere far in the future since it is spec-wide.

Also I would suggest considering using a smaller spec for the sample generation so that there are fewer classes, since we are only really after a single class that showcase that the enum matching is case insensitive?

@hamburml hamburml force-pushed the feature/AddEnumCaseInsensitiveJavaGen branch from d3cf6ae to 28a6f6b Compare July 1, 2026 16:01
@hamburml

hamburml commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

I have encountered it more than once, that is why i made this PR. And yes, the data providers are informed but can not always change their behaviour due to other consumers. This is also a client generator, not a server generator.

I can make the sample smaller and only add the enum classes - all the other microprofile generators have the same test scope so I thought we should behave the same.

@Mattias-Sehlstedt

Copy link
Copy Markdown
Contributor

I have encountered it more than once, that is why i made this PR. And yes, the data providers are informed but can not always change their behaviour due to other consumers. This is also a client generator, not a server generator.

I would not expect an application change from them, I would instead hope that they would correct their specification so that the enum actually stated the values that are produced. That is technically a breaking change from an OAS perspective, but given that they are already breaking their contract to begin with they should be semi-open to do a correction.

I can make the sample smaller and only add the enum classes - all the other microprofile generators have the same test scope so I thought we should behave the same.

Making a new spec is generally not preferred. But there is a high likelihood that some fitting spec exists from previous changes that have implemented this behavior.

Also note that I am not a maintainer, so everything here is my own opinions and suggestions, and not something that will grant an approve.

@hamburml hamburml force-pushed the feature/AddEnumCaseInsensitiveJavaGen branch from 28a6f6b to a565f28 Compare July 1, 2026 16:24
@hamburml

hamburml commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Unfortunately I can not make the example smaller, the generate-samples.sh regenerates all classes. So I guess it will stay that way.

Also note that I am not a maintainer, so everything here is my own opinions and suggestions, and not something that will grant an approve.

That is fair, as said a lot of openapi-generators already have that setting - so i guess it was simply missed here :) Thanks for the input.

@wing328 would love a review if you find some time. The docs do not need a change, the config option does already exist but was not used by the microprofile mustache files.

@@ -0,0 +1,13 @@
generatorName: java
outputDir: samples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignore-case

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tested locally and the build is successful

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.749 s
[INFO] Finished at: 2026-07-02T18:19:40+08:00
[INFO] ------------------------------------------------------------------------
[INFO] 9 goals, 9 executed
[INFO] Build cache (C:\Users\User\.m2\.develocity\build-cache\v2) removing files not accessed on or after Thu Jun 25 18:19:41 HKT 2026.
[INFO] Build cache (C:\Users\User\.m2\.develocity\build-cache\v2) cleanup deleted 0 files/directories.
[INFO] Build cache (C:\Users\User\.m2\.develocity\build-cache\v2) cleaned up in 0.007 secs.
[INFO]
[INFO] Publishing Build Scan to Develocity...
[INFO] https://community.develocity.cloud/s/htywrmwkw7hdo

@wing328 wing328 merged commit 63ce47f into OpenAPITools:master Jul 2, 2026
83 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jul 2, 2026
@hamburml hamburml deleted the feature/AddEnumCaseInsensitiveJavaGen branch July 2, 2026 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants