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

未关闭 适合新手
#1,433 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
backend

调研方向

阅读 AbstractJavaCodegen.java 第 488–515 行附近的内容,然后检查 processOpts() 和现有的 dateLibrary 分支。查看 java11 选项的描述方式,以及相关日期库的日期映射和 imports 配置方式。完成标准是:选择 dateLibrary=java11 后,无需单独设置 java11=true 选项,即可配置预期的 java.time 映射和 imports。

由索引模型根据 Issue 内容生成。

描述

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>
主要语言
Mustache
星标
299
派生
439
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

swagger-api/swagger-codegen-generators 的其他 Issue

查看 swagger-api/swagger-codegen-generators 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。