Skip to content

fix(java): handle formatted values in inner enum comparisons - #24937

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
KannaKim:fix-20952
Sep 15, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
KannaKim:fix-20952

Conversation

@KannaKim

@KannaKim KannaKim commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #20952.

Formatted inner enums such as type: string, format: uri can generate equalsIgnoreCase() calls on non-String Java values, causing compilation errors when useEnumCaseInsensitive=true.

This change updates 11 affected inner-enum templates to compare formatted string enum values using toString() when useEnumCaseInsensitive=true. Unformatted strings retain their existing behavior, and comparisons with the option disabled remain unchanged.

Null inputs are handled without calling toString() on them. Existing equality behavior is preserved for non-string enums and when useEnumCaseInsensitive=false.

Testing

All 26 parameterized cases pass across 13 generator/library configurations, with case-insensitive matching enabled and disabled.

Tests compile and execute generated fromValue methods in isolated enum fixtures, covering:

  • Plain strings, email, and custom string formats.
  • URI and UUID values.
  • Unformatted and formatted numeric enums.
  • Exact matches and differently cased inputs.
  • Nullable and non-nullable enums, including distinguishing Java null from the literal string "null".

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.
    @bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08) @KannaKim (2026/07)

Summary by cubic

Fixes #20952. Inner enum comparisons for string formats like uri no longer generate equalsIgnoreCase() calls on non-String values, so Java code using useEnumCaseInsensitive=true compiles.

  • Updates 11 inner-enum templates to use java.util.Objects.equals() when a format is present.
  • Unformatted string enums keep case-insensitive matching.
  • Formatted string enums mapped to Java String now match case-sensitively.
  • Adds parameterized regression tests that compile and run generated fromValue methods across 13 generator/library configurations.

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

Review in cubic

Convert formatted string enum values to strings for case-insensitive
comparison, handling null inputs safely. Preserve existing equality
when the option is disabled and for non-string enums.

Add compilation and runtime regression coverage across 13 generator
and library configurations.
@KannaKim
KannaKim marked this pull request as ready for review September 12, 2026 19:22

@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.

All reported issues were addressed across 13 files

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

Re-trigger cubic

@KannaKim
KannaKim marked this pull request as draft September 12, 2026 20:01
@KannaKim

Copy link
Copy Markdown
Contributor Author

The cubic review was probably based on my previous PR description. I’ve updated the description to accurately reflect the implementation.

@KannaKim
KannaKim marked this pull request as ready for review September 12, 2026 21:03

@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.

No issues found across 13 files

Re-trigger cubic

@@ -0,0 +1,53 @@
openapi: 3.0.3

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.

FYI. Tested with this (using the default okhttp-gson library) but the output won't compile:

[ERROR] C:\Users\User\AppData\Local\Temp\enumtest2\src\main\java\org\openapitools\client\model\Example.java:[321,18] error: no suitable method found for value(UUID)
[ERROR]     method JsonWriter.value(String) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to String)
[ERROR]     method JsonWriter.value(boolean) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to boolean)
[ERROR]     method JsonWriter.value(Boolean) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to Boolean)
[ERROR]     method JsonWriter.value(float) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to float)
[ERROR]     method JsonWriter.value(double) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to double)
[ERROR]     method JsonWriter.value(long) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to long)
[ERROR]     method JsonWriter.value(Number) is not applicable
[ERROR]       (argument mismatch; UUID cannot be converted to Number)
[ERROR] C:\Users\User\AppData\Local\Temp\enumtest2\src\main\java\org\openapitools\client\model\Example.java:[326,32] error: cannot find symbol
[ERROR]   symbol:   method nextUUID()
[ERROR]   location: variable jsonReader of type JsonReader
[ERROR] C:\Users\User\AppData\Local\Temp\enumtest2\src\main\java\org\openapitools\client\model\Example.java:[332,30] error: cannot find symbol
[ERROR]   symbol:   method getAsUUID()
[ERROR]   location: variable jsonElement of type JsonElement

Not related to this change. Just another edge case we need to address one day.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted, I can make separate PR for this.

@wing328

wing328 commented Sep 15, 2026

Copy link
Copy Markdown
Member

thanks for the PR.

I did a test with

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i https://raw.githubusercontent.com/KannaKim/openapi-generator/1a102a1226560e5c7482f2bb1714e2fff877305e/modules/openapi-generator/src/test/resources/3_0/issue_20952_inner_enum_comparison.yaml -o /tmp/enumtest2/

But don't see any change when compared with the latest master.

Are you seeing the same or I'm no testing this change correctly ?

@KannaKim

Copy link
Copy Markdown
Contributor Author

thanks for the PR.

I did a test with

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i https://raw.githubusercontent.com/KannaKim/openapi-generator/1a102a1226560e5c7482f2bb1714e2fff877305e/modules/openapi-generator/src/test/resources/3_0/issue_20952_inner_enum_comparison.yaml -o /tmp/enumtest2/

But don't see any change when compared with the latest master.

Are you seeing the same or I'm no testing this change correctly ?

Hi, thanks for testing. It looks like useEnumCaseInsensitive=true was omitted in your command. I just ran test on my end using

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i https://raw.githubusercontent.com/KannaKim/openapi-generator/1a102a1226560e5c7482f2bb1714e2fff877305e/modules/openapi-generator/src/test/resources/3_0/issue_20952_inner_enum_comparison.yaml -o /tmp/enumtest2/ --additional-properties=useEnumCaseInsensitive=true

generated comparison changed from

b.value.equalsIgnoreCase(value)

to

b.value.toString().equalsIgnoreCase(value == null ? null : value.toString())

@wing328

wing328 commented Sep 15, 2026

Copy link
Copy Markdown
Member

Ah ok. I missed that. Thanks for the details and the fix

@wing328
wing328 merged commit bc2368e into OpenAPITools:master Sep 15, 2026
15 checks passed
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.

Inner URI Enums with useEnumCaseInsensitive causes compilation errors

2 participants