Skip to content

Commit

Permalink
Merge pull request swagger-api#9151 from stijnkoopal/java8-instant
Browse files Browse the repository at this point in the history
Add support for java.time.Instant for java generators
  • Loading branch information
HugoMario authored Oct 3, 2019
2 parents 680b32f + 34a0893 commit c9252e8
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public AbstractJavaCodegen() {
modelDocTemplateFiles.put("model_doc.mustache", ".md");
apiDocTemplateFiles.put("api_doc.mustache", ".md");

hideGenerationTimestamp = false;
hideGenerationTimestamp = false;

setReservedWordsLowerCase(
Arrays.asList(
// used as internal variables, can collide with parameter names
Expand Down Expand Up @@ -167,6 +167,7 @@ public AbstractJavaCodegen() {
dateOptions.put("java8", "Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets \"" + JAVA8_MODE + "\" to true");
dateOptions.put("threetenbp", "Backport of JSR310 (preferred for jdk < 1.8)");
dateOptions.put("java8-localdatetime", "Java 8 using LocalDateTime (for legacy app only)");
dateOptions.put("java8-instant", "Java 8 using Instant");
dateOptions.put("joda", "Joda (for legacy app only)");
dateOptions.put("legacy", "Legacy java.util.Date (if you really have a good reason not to use threetenbp");
dateLibrary.setEnum(dateOptions);
Expand Down Expand Up @@ -440,13 +441,19 @@ public void processOpts() {
} else if (dateLibrary.startsWith("java8")) {
additionalProperties.put("java8", "true");
additionalProperties.put("jsr310", "true");
typeMapping.put("date", "LocalDate");
importMapping.put("LocalDate", "java.time.LocalDate");
if ("java8-localdatetime".equals(dateLibrary)) {
typeMapping.put("date", "LocalDate");
typeMapping.put("DateTime", "LocalDateTime");
importMapping.put("LocalDate", "java.time.LocalDate");
importMapping.put("LocalDateTime", "java.time.LocalDateTime");
} else if ("java8-instant".equals(dateLibrary)) {
typeMapping.put("date", "Instant");
typeMapping.put("DateTime", "Instant");
importMapping.put("Instant", "java.time.Instant");
} else {
typeMapping.put("date", "LocalDate");
typeMapping.put("DateTime", "OffsetDateTime");
importMapping.put("LocalDate", "java.time.LocalDate");
importMapping.put("OffsetDateTime", "java.time.OffsetDateTime");
}
} else if (dateLibrary.equals("legacy")) {
Expand Down

0 comments on commit c9252e8

Please sign in to comment.