[Bug]: Cannot target java LocalDateTime via type mappings
还没有人认领这个 Issue。
评估
调研方向
通过 Maven 插件,使用提供的 OpenAPI 3.1 规范以及所示的 typeMappings 和 importMappings 重现该问题。首先跟踪 Java 生成器对已映射类型的保留字处理;当生成的代码使用 java.time.LocalDateTime 而不是 ModelLocalDateTime,并且能够编译时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
Description
Using typeMappings I cannot specify a class with in-built support due to reserved word checking.
The OpenAPI specification defined "date-time" as a format value for strings, but that allows anything in ISO-8601. I want to declare in my spec whether it should be local date-time (no suffix), Zulu (Z suffix), or offer (+-nnnn suffix)
I am trying to do this with the following type mappings
typeMappings:
string+date-time-local: LocalDateTime
string+date: LocalDate
string+time: LocalTime
string+date-time-duration: Duration
string+date-period: Period
string+date-time-zoned: ZonedDateTime
string+date-time-offset: OffsetDateTime
string+timestamp: Instant
importMappings:
LocalDateTime: 'java.time.LocalDateTime'
LocalDate: 'java.time.LocalDate'
LocalTime: 'java.time.LocalTime'
ZonedDateTime: 'java.time.ZonedDateTime'
OffsetDateTime: 'java.time.OffsetDateTime'
Instant: 'java.time.Instant'
Duration: 'java.time.Duration'
Period: 'java.time.Period'
"LocalDate" is treated as a reserved word to avoid conflict between a spec declaring a model of that name and the java.time classes. I do not want to declare anything new but instead actually use the standard java.time classes.
When doing this, I receive this warning [WARNING] LocalDate (reserved word) cannot be used as model name. Renamed to ModelLocalDate, and it generates code using ModelLocalDate. I cannot see any obvious way of achieving what I need to do,.
Swagger Codegen Version
7.13.0 (via maven plugin)
Language / Generator
Java
OpenAPI/Swagger Spec
openapi: 3.1.0
info:
title: Example
version: 1.0.0
paths:
/example:
post:
summary: example
operationId: example
parameters:
requestBody:
content:
application/json:
schema:
$ref: "#/components/schemas/Example"
components:
schemas:
Example:
type: object
properties:
localDate:
type: string
format: date-time-local
Steps to Reproduce
Attempt to generate the above OpenAPI specification using the type mappings above.
Expected Behaviour
Code is generated which utilised java.time.LocalDateTime
Actual Behavior
Code is generated using ModelLocalDateTime, which does not compile
Related
This would appear to be related to the changes in https://github.com/OpenAPITools/openapi-generator/pull/16276
Checklist
- I have searched the existing issues to make sure this is not a duplicate.
- I have included a minimal and reproducible spec example.
- I have explained how to reproduce the issue.
- I have specified which generator/language is affected.
- 主要语言
- Mustache
- 星标
- 17.8k
- 派生
- 6k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swagger-api/swagger-codegen 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
swagger-api/swagger-codegen#12755 ·
-
难度 2/5 1-3 小时 新手友好度 62/100
swagger-api/swagger-codegen#12445 ·
-
security vulnerability
难度 1/5 1 小时以内 新手友好度 62/100
swagger-api/swagger-codegen#11942 ·
-
[JAVA] Non compilable enums generated with property errorOnUnknownEnum=true可能已有人在做 @HiagoW 于 1458 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
swagger-api/swagger-codegen#11812 · 1 个 reaction ·
-
security vulnerability
难度 2/5 1-3 小时 新手友好度 65/100
swagger-api/swagger-codegen#11594 ·
查看 swagger-api/swagger-codegen 的全部 Issue
相似的 Issue
-
Frontmatter next to `src:` is applied to every imported slide, not only the first (undocumented)未关闭
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 62/100
Fission-AI/OpenSpec#2084 ·
维护者通常 2 天内回复
-
[scanner] check:spelling skips blog/ — posts and author metadata are never spell-checked可能已有人在做 @hivecommons-hive 今天认领。 未关闭agent/scanner bug hive/covered-by-pr hive/hosted-available-lke648397-260827-5n31
难度 1/5 1 小时以内 新手友好度 72/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 74/100
MatAtBread/matbot#99 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
rlaope/oh-my-hermes#2129 · 1 条评论 ·
维护者通常 1 天内回复