fix(java-spring): handle UUID type in enum values generation#23589
fix(java-spring): handle UUID type in enum values generation#23589wing328 merged 2 commits intoOpenAPITools:masterfrom
Conversation
|
@wing328 result of your comment #23516 (comment) |
|
cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) |
|
I did a test with but the output won't compile. am I testing this change correctly? |
For I cannot confirm the errors in |
|
cc @cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09) @martin-mfg (2023/08) |
|
@renatomameli @wing328 The compilation error for I've introduced a regression with the introduction of jspecify, sorry for the inconvenience . The missing UUID import is due to It does not import UUID, URI, BigDecimal... It makes sense to add them as well. Either you unconditionally import them in the template, either you add them programmatically in additionalProperties |
Yes the missing imports are fixed here: #23516 |
confirmed the output compiles without issues when tested with both PRs merged into master. |
|
FYI. samples updated via bf51147 |
Problem
When generating Spring enums with
format: uuid, the generated code incorrectly uses string literals instead of the properUUID.fromString(...)method.This issue came up here: #23516
Solution
Add UUID handling in AbstractJavaCodegen.toEnumValue() following the existing URI pattern:
Test
Added contractWithUuidEnumShouldGenerateValidEnum() test that verifies
UUID.fromString()is used for enum valuesPR checklist
(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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Fix enum generation for
format: uuidin Java/Spring. Enums now callUUID.fromString(...)and store realUUIDvalues instead of strings.UUIDinAbstractJavaCodegen.toEnumValue()by returningUUID.fromString("...").contractWithUuidEnumShouldGenerateValidEnumand sample spec to verifyUUID.fromString(...)and aprivate final UUID value.Written for commit 6cb572a. Summary will update on new commits.