OpenAPITools / OpenAPITools/openapi-generator
[JAVA] incorrect import mapping of DateTime
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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");
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java and review the dateLibrary type and import mappings. Reproduce generation with the provided schema using a non-joda Java date library, then verify that generated components use valid imports for date and date-time types across the affected libraries.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100