openapi-generator: [JAVA] incorrect import mapping of DateTime
Description
Generation of java components fails when joda is not used due to incorrect mapping of imports
openapi-generator version
3.3.2-SNAPSHOT
OpenAPI declaration file content or url
---
components:
schemas:
Dummy:
type: object
properties:
dt:
type: date
ts:
type: date-time
Command line used for generation
Steps to reproduce
Generate with any Java generator with dateLibrary other then joda
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/pull/1313
Suggest a fix/enhancement
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
index c119400db..15458ccb7 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java
@@ -486,7 +486,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
typeMapping.put("date", "LocalDate");
typeMapping.put("DateTime", "OffsetDateTime");
importMapping.put("LocalDate", "org.threeten.bp.LocalDate");
- importMapping.put("OffsetDateTime", "org.threeten.bp.OffsetDateTime");
+ importMapping.put("DateTime", "org.threeten.bp.OffsetDateTime");
} else if ("joda".equals(dateLibrary)) {
additionalProperties.put("joda", "true");
typeMapping.put("date", "LocalDate");
@@ -500,10 +500,10 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
importMapping.put("LocalDate", "java.time.LocalDate");
if ("java8-localdatetime".equals(dateLibrary)) {
typeMapping.put("DateTime", "LocalDateTime");
- importMapping.put("LocalDateTime", "java.time.LocalDateTime");
+ importMapping.put("DateTime", "java.time.LocalDateTime");
} else {
typeMapping.put("DateTime", "OffsetDateTime");
- importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
+ importMapping.put("DateTime", "java.time.OffsetDateTime");
}
} else if (dateLibrary.equals("legacy")) {
additionalProperties.put("legacyDates", "true");
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 2
- Comments: 23 (12 by maintainers)
As a workaround try this:
so that’s not us. We should open an issue in swagger-parser
I get it : your OAS is wrong. The type of
dtandtsshould bestringwithformat: dateandformat: date-timerespectively. Now there remains 2 issues:threetenbpimports instead ofjava.timeones. This doesn’t happen when generating from the CLI.cc @jimschubert for the maven plugin