diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 92a3f76b7600..f058457e65c8 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -4959,6 +4959,15 @@ public String getLibrary() { return library; } + /** + * check if current active library equals to passed + * @param library - library to be compared with + * @return + */ + public final boolean isLibrary(String library) { + return library.equals(this.library); + } + /** * Set Git host. * diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 0190175004a8..89331cfb6826 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -39,7 +39,6 @@ import static com.google.common.base.CaseFormat.LOWER_CAMEL; import static com.google.common.base.CaseFormat.UPPER_UNDERSCORE; import static java.util.Collections.sort; -import static org.openapitools.codegen.utils.OnceLogger.once; import static org.openapitools.codegen.utils.StringUtils.camelize; public class JavaClientCodegen extends AbstractJavaCodegen @@ -310,13 +309,16 @@ public void processOpts() { supportingFiles.add(new SupportingFile("ServerVariable.mustache", invokerFolder, "ServerVariable.java")); supportingFiles.add(new SupportingFile("openapi.mustache", "api", "openapi.yaml")); + if (dateLibrary.equals("java8") && (isLibrary(WEBCLIENT) || isLibrary(VERTX) || isLibrary(RESTTEMPLATE) || isLibrary(RESTEASY) || isLibrary(MICROPROFILE) || isLibrary(JERSEY2))) { + supportingFiles.add(new SupportingFile("JavaTimeFormatter.mustache", invokerFolder, "JavaTimeFormatter.java")); + } - if (!(RESTTEMPLATE.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || NATIVE.equals(getLibrary()) || MICROPROFILE.equals(getLibrary()))) { + if (!(RESTTEMPLATE.equals(getLibrary()) || isLibrary(REST_ASSURED) || isLibrary(NATIVE) || isLibrary(MICROPROFILE))) { supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java")); } // google-api-client doesn't use the OpenAPI auth, because it uses Google Credential directly (HttpRequestInitializer) - if (!(GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || NATIVE.equals(getLibrary()) || MICROPROFILE.equals(getLibrary()))) { + if (!(isLibrary(GOOGLE_API_CLIENT) || isLibrary(REST_ASSURED) || isLibrary(NATIVE) || isLibrary(MICROPROFILE))) { supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java")); supportingFiles.add(new SupportingFile("auth/HttpBearerAuth.mustache", authFolder, "HttpBearerAuth.java")); supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java")); diff --git a/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache index b2e3b1986512..262110a2992c 100644 --- a/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/ApiClient.mustache @@ -12,6 +12,7 @@ import com.fasterxml.jackson.datatype.joda.JodaModule; {{/joda}} {{#java8}} import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import java.time.OffsetDateTime; {{/java8}} {{#threetenbp}} import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule; @@ -67,7 +68,7 @@ import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} {{>generatedAnnotation}} -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { private Map defaultHeaderMap = new HashMap(); private Map defaultCookieMap = new HashMap(); private String basePath = "{{{basePath}}}"; @@ -499,7 +500,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate((Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { diff --git a/modules/openapi-generator/src/main/resources/Java/JavaTimeFormatter.mustache b/modules/openapi-generator/src/main/resources/Java/JavaTimeFormatter.mustache new file mode 100644 index 000000000000..9afcea99a155 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/Java/JavaTimeFormatter.mustache @@ -0,0 +1,32 @@ +{{>licenseInfo}} +package {{invokerPackage}}; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +{{>generatedAnnotation}} +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +} diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache index 48c9d986bb53..4ccf4e9cb09c 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/jersey2/ApiClient.mustache @@ -55,6 +55,9 @@ import java.util.List; import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +{{#java8}} +import java.time.OffsetDateTime; +{{/java8}} import java.net.URLEncoder; @@ -77,7 +80,7 @@ import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} {{>generatedAnnotation}} -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { protected Map defaultHeaderMap = new HashMap(); protected Map defaultCookieMap = new HashMap(); protected String basePath = "{{{basePath}}}"; @@ -695,7 +698,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate((Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache index 16ec4c4508f0..8f3486eb5db6 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resteasy/ApiClient.mustache @@ -22,6 +22,9 @@ import java.util.Map.Entry; import java.util.TimeZone; import java.util.regex.Matcher; import java.util.regex.Pattern; +{{#java8}} +import java.time.OffsetDateTime; +{{/java8}} import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -48,7 +51,7 @@ import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} {{>generatedAnnotation}} -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { private Map defaultHeaderMap = new HashMap(); private Map defaultCookieMap = new HashMap(); private String basePath = "{{{basePath}}}"; @@ -333,7 +336,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate((Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { if(b.length() > 0) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache index f4add57c3e10..190670a65681 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/resttemplate/ApiClient.mustache @@ -64,6 +64,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; +{{#java8}} +import java.time.OffsetDateTime; +{{/java8}} import {{invokerPackage}}.auth.Authentication; {{#hasHttpBasicMethods}} @@ -81,7 +84,7 @@ import {{invokerPackage}}.auth.OAuth; {{>generatedAnnotation}} @Component("{{invokerPackage}}.ApiClient") -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { public enum CollectionFormat { CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null); @@ -402,7 +405,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate( (Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection) param) { if(b.length() > 0) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache index c7d0056fef87..c57ff1cdea2f 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/vertx/ApiClient.mustache @@ -31,6 +31,9 @@ import io.vertx.ext.web.client.HttpResponse; import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; +{{#java8}} +import java.time.OffsetDateTime; +{{/java8}} import java.text.DateFormat; import java.util.*; import java.util.function.Consumer; @@ -40,7 +43,7 @@ import java.util.regex.Pattern; import static java.util.stream.Collectors.toMap; {{>generatedAnnotation}} -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { private static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); private static final OpenOptions FILE_DOWNLOAD_OPTIONS = new OpenOptions().setCreate(true).setTruncateExisting(true); @@ -291,7 +294,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate((Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for (Object o : (Collection) param) { if (b.length() > 0) { diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache index 712ac17c6374..ae3c27272a08 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache @@ -57,6 +57,9 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; +{{#java8}} +import java.time.OffsetDateTime; +{{/java8}} import {{invokerPackage}}.auth.Authentication; import {{invokerPackage}}.auth.HttpBasicAuth; @@ -67,7 +70,7 @@ import {{invokerPackage}}.auth.OAuth; {{/hasOAuthMethods}} {{>generatedAnnotation}} -public class ApiClient { +public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} { public enum CollectionFormat { CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null); @@ -350,7 +353,9 @@ public class ApiClient { return ""; } else if (param instanceof Date) { return formatDate( (Date) param); - } else if (param instanceof Collection) { + } {{#java8}}else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); + } {{/java8}}else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection) param) { if(b.length() > 0) { diff --git a/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES b/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES index 25518623866e..2d4a06729dd9 100644 --- a/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES +++ b/samples/client/petstore/java/jersey2-java8/.openapi-generator/FILES @@ -70,6 +70,7 @@ src/main/java/org/openapitools/client/ApiException.java src/main/java/org/openapitools/client/ApiResponse.java src/main/java/org/openapitools/client/Configuration.java src/main/java/org/openapitools/client/JSON.java +src/main/java/org/openapitools/client/JavaTimeFormatter.java src/main/java/org/openapitools/client/Pair.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index a0529ef23392..8f8b62e84be1 100644 --- a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -47,6 +47,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.time.OffsetDateTime; import java.net.URLEncoder; @@ -64,7 +65,7 @@ import org.openapitools.client.auth.OAuth; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ApiClient { +public class ApiClient extends JavaTimeFormatter { protected Map defaultHeaderMap = new HashMap(); protected Map defaultCookieMap = new HashMap(); protected String basePath = "http://petstore.swagger.io:80/v2"; @@ -612,6 +613,8 @@ public String parameterToString(Object param) { return ""; } else if (param instanceof Date) { return formatDate((Date) param); + } else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { diff --git a/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java new file mode 100644 index 000000000000..65807b8a9c92 --- /dev/null +++ b/samples/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java @@ -0,0 +1,43 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +} diff --git a/samples/client/petstore/java/vertx/.openapi-generator/FILES b/samples/client/petstore/java/vertx/.openapi-generator/FILES index 82fed67a26fb..5e33964f3a9d 100644 --- a/samples/client/petstore/java/vertx/.openapi-generator/FILES +++ b/samples/client/petstore/java/vertx/.openapi-generator/FILES @@ -68,6 +68,7 @@ src/main/AndroidManifest.xml src/main/java/org/openapitools/client/ApiClient.java src/main/java/org/openapitools/client/ApiException.java src/main/java/org/openapitools/client/Configuration.java +src/main/java/org/openapitools/client/JavaTimeFormatter.java src/main/java/org/openapitools/client/Pair.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java diff --git a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java index 9f059c98c96a..07b0da20acc0 100644 --- a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/ApiClient.java @@ -29,6 +29,7 @@ import io.vertx.ext.web.client.WebClient; import io.vertx.ext.web.client.WebClientOptions; +import java.time.OffsetDateTime; import java.text.DateFormat; import java.util.*; import java.util.function.Consumer; @@ -38,7 +39,7 @@ import static java.util.stream.Collectors.toMap; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ApiClient { +public class ApiClient extends JavaTimeFormatter { private static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?"); private static final OpenOptions FILE_DOWNLOAD_OPTIONS = new OpenOptions().setCreate(true).setTruncateExisting(true); @@ -287,6 +288,8 @@ public String parameterToString(Object param) { return ""; } else if (param instanceof Date) { return formatDate((Date) param); + } else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for (Object o : (Collection) param) { diff --git a/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/JavaTimeFormatter.java b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/JavaTimeFormatter.java new file mode 100644 index 000000000000..65807b8a9c92 --- /dev/null +++ b/samples/client/petstore/java/vertx/src/main/java/org/openapitools/client/JavaTimeFormatter.java @@ -0,0 +1,43 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +} diff --git a/samples/client/petstore/java/webclient/.openapi-generator/FILES b/samples/client/petstore/java/webclient/.openapi-generator/FILES index bc6035c8a0e8..59f7fd0d31ec 100644 --- a/samples/client/petstore/java/webclient/.openapi-generator/FILES +++ b/samples/client/petstore/java/webclient/.openapi-generator/FILES @@ -66,6 +66,7 @@ pom.xml settings.gradle src/main/AndroidManifest.xml src/main/java/org/openapitools/client/ApiClient.java +src/main/java/org/openapitools/client/JavaTimeFormatter.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java src/main/java/org/openapitools/client/ServerVariable.java diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java index 0769fb81d3eb..a913b6c1cb7d 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java @@ -57,6 +57,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TimeZone; +import java.time.OffsetDateTime; import org.openapitools.client.auth.Authentication; import org.openapitools.client.auth.HttpBasicAuth; @@ -65,7 +66,7 @@ import org.openapitools.client.auth.OAuth; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ApiClient { +public class ApiClient extends JavaTimeFormatter { public enum CollectionFormat { CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null); @@ -346,6 +347,8 @@ public String parameterToString(Object param) { return ""; } else if (param instanceof Date) { return formatDate( (Date) param); + } else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection) param) { diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/JavaTimeFormatter.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/JavaTimeFormatter.java new file mode 100644 index 000000000000..65807b8a9c92 --- /dev/null +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/JavaTimeFormatter.java @@ -0,0 +1,43 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +} diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/.openapi-generator/FILES b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/.openapi-generator/FILES index e1fd40df0ca6..c209475dd6e8 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/.openapi-generator/FILES @@ -24,6 +24,7 @@ src/main/java/org/openapitools/client/ApiException.java src/main/java/org/openapitools/client/ApiResponse.java src/main/java/org/openapitools/client/Configuration.java src/main/java/org/openapitools/client/JSON.java +src/main/java/org/openapitools/client/JavaTimeFormatter.java src/main/java/org/openapitools/client/Pair.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java index 543a3ae4ff1e..ce0383039f6e 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/ApiClient.java @@ -46,6 +46,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.time.OffsetDateTime; import java.net.URLEncoder; @@ -62,7 +63,7 @@ import org.openapitools.client.auth.ApiKeyAuth; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ApiClient { +public class ApiClient extends JavaTimeFormatter { protected Map defaultHeaderMap = new HashMap(); protected Map defaultCookieMap = new HashMap(); protected String basePath = "http://localhost"; @@ -493,6 +494,8 @@ public String parameterToString(Object param) { return ""; } else if (param instanceof Date) { return formatDate((Date) param); + } else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { diff --git a/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/JavaTimeFormatter.java b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/JavaTimeFormatter.java new file mode 100644 index 000000000000..02ecd6395807 --- /dev/null +++ b/samples/openapi3/client/petstore/java/jersey2-java8-special-characters/src/main/java/org/openapitools/client/JavaTimeFormatter.java @@ -0,0 +1,43 @@ +/* + * test + * test + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +} diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/.openapi-generator/FILES b/samples/openapi3/client/petstore/java/jersey2-java8/.openapi-generator/FILES index c05e6308f676..042f47d42d85 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/.openapi-generator/FILES +++ b/samples/openapi3/client/petstore/java/jersey2-java8/.openapi-generator/FILES @@ -103,6 +103,7 @@ src/main/java/org/openapitools/client/ApiException.java src/main/java/org/openapitools/client/ApiResponse.java src/main/java/org/openapitools/client/Configuration.java src/main/java/org/openapitools/client/JSON.java +src/main/java/org/openapitools/client/JavaTimeFormatter.java src/main/java/org/openapitools/client/Pair.java src/main/java/org/openapitools/client/RFC3339DateFormat.java src/main/java/org/openapitools/client/ServerConfiguration.java diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java index af327d787786..8539f7f9a3f0 100644 --- a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/ApiClient.java @@ -47,6 +47,7 @@ import java.util.Arrays; import java.util.ArrayList; import java.util.Date; +import java.time.OffsetDateTime; import java.net.URLEncoder; @@ -65,7 +66,7 @@ import org.openapitools.client.auth.OAuth; @javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") -public class ApiClient { +public class ApiClient extends JavaTimeFormatter { protected Map defaultHeaderMap = new HashMap(); protected Map defaultCookieMap = new HashMap(); protected String basePath = "http://petstore.swagger.io:80/v2"; @@ -691,6 +692,8 @@ public String parameterToString(Object param) { return ""; } else if (param instanceof Date) { return formatDate((Date) param); + } else if (param instanceof OffsetDateTime) { + return formatOffsetDateTime((OffsetDateTime) param); } else if (param instanceof Collection) { StringBuilder b = new StringBuilder(); for(Object o : (Collection)param) { diff --git a/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java new file mode 100644 index 000000000000..65807b8a9c92 --- /dev/null +++ b/samples/openapi3/client/petstore/java/jersey2-java8/src/main/java/org/openapitools/client/JavaTimeFormatter.java @@ -0,0 +1,43 @@ +/* + * OpenAPI Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * The version of the OpenAPI document: 1.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package org.openapitools.client; + +import java.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen") +public class JavaTimeFormatter { + + private DateTimeFormatter offsetDateTimeFormatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME; + + public DateTimeFormatter getOffsetDateTimeFormatter() { + return offsetDateTimeFormatter; + } + + public void setOffsetDateTimeFormatter(DateTimeFormatter offsetDateTimeFormatter) { + this.offsetDateTimeFormatter = offsetDateTimeFormatter; + } + + public OffsetDateTime parseOffsetDateTime(String str) { + try { + return OffsetDateTime.parse(str, offsetDateTimeFormatter); + } catch (DateTimeParseException e) { + throw new RuntimeException(e); + } + } + + public String formatOffsetDateTime(OffsetDateTime offsetDateTime) { + return offsetDateTimeFormatter.format(offsetDateTime); + } +}