fix(java): handle formatted values in inner enum comparisons - #24937
Conversation
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.
There was a problem hiding this comment.
All reported issues were addressed across 13 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
|
The cubic review was probably based on my previous PR description. I’ve updated the description to accurately reflect the implementation. |
| @@ -0,0 +1,53 @@ | |||
| openapi: 3.0.3 | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Noted, I can make separate PR for this.
|
thanks for the PR. I did a test with But don't see any change when compared with the latest 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 generated comparison changed from b.value.equalsIgnoreCase(value)to b.value.toString().equalsIgnoreCase(value == null ? null : value.toString()) |
|
Ah ok. I missed that. Thanks for the details and the fix |
Description
Fixes #20952.
Formatted inner enums such as
type: string, format: urican generateequalsIgnoreCase()calls on non-String Java values, causing compilation errors whenuseEnumCaseInsensitive=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 whenuseEnumCaseInsensitive=false.Testing
All 26 parameterized cases pass across 13 generator/library configurations, with case-insensitive matching enabled and disabled.
Tests compile and execute generated
fromValuemethods in isolated enum fixtures, covering:nullfrom the literal string"null".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.
@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
urino longer generateequalsIgnoreCase()calls on non-String values, so Java code usinguseEnumCaseInsensitive=truecompiles.java.util.Objects.equals()when a format is present.Stringnow match case-sensitively.fromValuemethods across 13 generator/library configurations.Written for commit e0ecda9. Summary will update on new commits.