Skip to content

fix(java-spring): add missing imports for converter (#23325)#23516

Open
renatomameli wants to merge 1 commit intoOpenAPITools:masterfrom
renatomameli:fix-missing-uri
Open

fix(java-spring): add missing imports for converter (#23325)#23516
renatomameli wants to merge 1 commit intoOpenAPITools:masterfrom
renatomameli:fix-missing-uri

Conversation

@renatomameli
Copy link
Copy Markdown
Contributor

@renatomameli renatomameli commented Apr 10, 2026

closes #23325

The converter.mustache template uses {{{dataType}}} which resolves to short names like URI, UUID or BigDecimal for Java, but the template never imported those types.
A previous fix attempt in SpringCodegen.postProcessModelsEnum() tried to work around this by overwriting cm.dataType with the fully qualified name from importMapping (e.g. URIjava.net.URI). However, this approach pollutes the dataType globally — the FQN then also leaks into the enum model classes themselves, which is undesirable. An alternative would be to use vendor-extensions if desired.

But this PR follows the same pattern already established by model.mustache, which hardcodes commonly needed imports like java.net.URI and java.util.* (line 44) rather than dynamically resolving them. The fix:
converter.mustache: Add import java.net.URI; and import java.util.UUID; — the two non-java.lang types that can appear as enum dataType values.

Tests: Updated to assert that imports are present and short names are used in the converter.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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


Summary by cubic

Adds missing imports to Spring converter.mustache so generated enum converters compile for URI, UUID, and numeric enums. Adds java.math.BigDecimal, java.net.URI, and java.util.UUID imports; updates samples and adds tests asserting the imports and short type names in EnumConverterConfiguration.java.

Written for commit 41aa7db. Summary will update on new commits.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 5 files

@renatomameli renatomameli force-pushed the fix-missing-uri branch 3 times, most recently from d195e2c to 8f05a40 Compare April 10, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][spring/spring-boot] Missing import of URI in Generated EnumConverter

2 participants