[Java] Add USE_ENUM_CASE_INSENSITIVE for java client generator#24180
Conversation
bda1571 to
4f440c9
Compare
There was a problem hiding this comment.
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> | |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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>
| [**void**](Void.md) | |
| null (empty response body) |
4f440c9 to
83dbbaa
Compare
|
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? |
|
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... |
83dbbaa to
d3cf6ae
Compare
|
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? |
d3cf6ae to
28a6f6b
Compare
|
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. |
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.
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. |
28a6f6b to
a565f28
Compare
|
Unfortunately I can not make the example smaller, the generate-samples.sh regenerates all classes. So I guess it will stay that way.
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 | |||
There was a problem hiding this comment.
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
Add USE_ENUM_CASE_INSENSITIVE for java client generator, also add test
PR checklist
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.
Summary by cubic
Adds case-insensitive enum matching to the Java MicroProfile client generator. When
useEnumCaseInsensitiveis enabled, generated enums accept values regardless of case infromValueand duringjacksondeserialization.New Features
additionalProperties.useEnumCaseInsensitivefor thejavagenerator (microprofilelibrary); when enabled, usesequalsIgnoreCaseinenumClass.mustache(including the Jackson enum deserializer) andenumOuterClass.mustache.bin/configs/java-microprofile-rest-client-3.0-jackson-ignore-case.yamland a generated sample undersamples/client/petstore/java/microprofile-rest-client-3.0-jackson-ignore-caseto validateequalsIgnoreCasebehavior with MicroProfile Rest Client 3.0 andjackson.Migration
--additional-properties useEnumCaseInsensitive=true(oruseEnumCaseInsensitive: truein your config).Written for commit a565f28. Summary will update on new commits.