Setting dateLibrary=java11 fails to map "java.time" types

Open Beginner friendly
#1,433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java
Domain
backend

Research direction

Read AbstractJavaCodegen.java around lines 488–515, then inspect processOpts() and the existing dateLibrary branches. Check how the java11 option is described and how date mappings and imports are configured for related date libraries. Done means selecting dateLibrary=java11 configures the expected java.time mappings and imports without requiring a separate java11=true option.

Written by the indexing model from the issue text.

Description

https://github.com/swagger-api/swagger-codegen-generators/blob/master/src/main/java/io/swagger/codegen/v3/generators/java/AbstractJavaCodegen.java#L488-L515

In the above source code of AbstractJavaCodegen, the dateLibrary enum registers "java11" in the CLI options list. However, the processOpts() method only checks for "threetenbp", "joda", dateLibrary.startsWith("java8"), and "legacy":
• Missing if branch. Because there is no else if ("java11".equals(dateLibrary)) block in AbstractJavaCodegen.processOpts(), the generator skips setting up java.time type mappings and imports.
• Fallback to java.util.Date. By default, AbstractJavaCodegen initializes typeMapping.put("date", "Date"), which resolves to java.util.Date when no dateLibrary branch overrides it.
• Flag discrepancy. Although the CLI description claims "java11" automatically sets java11=true, the code only reads java11 if you explicitly pass true in your configuration.

This leads to the required strange combination of configuration options:

<configOptions>
    <!-- don't use "java11" - a bug in swagger lets this fall back to "legacy" -->
    <dateLibrary>java8</dateLibrary>
    <java11>true</java11>
    <jakarta>true</jakarta>
</configOptions>
Dominant language
Mustache
Stars
299
Forks
439
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from swagger-api/swagger-codegen-generators

All issues in swagger-api/swagger-codegen-generators

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.