Skip to content

Commit

Permalink
[Java] fix generation for JavaTimeFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
borsch committed Jan 8, 2021
1 parent 319bd7e commit 03d31bf
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 131 deletions.
2 changes: 1 addition & 1 deletion bin/configs/java-vertx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ templateDir: modules/openapi-generator/src/main/resources/Java
additionalProperties:
artifactId: petstore-vertx
hideGenerationTimestamp: "true"
dateLibrary: java8
dateLibrary: java8-localdatetime
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ public void processOpts() {
setDateLibrary(additionalProperties.get("dateLibrary").toString());
}

additionalProperties.put("dateLibrary_" + dateLibrary, "true");
if ("threetenbp".equals(dateLibrary)) {
additionalProperties.put("threetenbp", "true");
additionalProperties.put("jsr310", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import com.fasterxml.jackson.datatype.joda.JodaModule;
{{/joda}}
{{#java8}}
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/dateLibrary_java8}}
{{/java8}}
{{#threetenbp}}
import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
Expand Down Expand Up @@ -68,7 +70,7 @@ import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}}

{{>generatedAnnotation}}
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_java8}} {
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
private String basePath = "{{{basePath}}}";
Expand Down Expand Up @@ -500,9 +502,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection<?>)param) {
if(b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Date;
{{#java8}}
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/java8}}
{{/dateLibrary_java8}}

import java.net.URLEncoder;

Expand All @@ -80,7 +80,7 @@ import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}}

{{>generatedAnnotation}}
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_java8}} {
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
protected String basePath = "{{{basePath}}}";
Expand Down Expand Up @@ -720,9 +720,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
{{#java8}}
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/java8}}
{{/dateLibrary_java8}}

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
Expand All @@ -51,7 +51,7 @@ import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}}

{{>generatedAnnotation}}
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_java8}} {
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
private String basePath = "{{{basePath}}}";
Expand Down Expand Up @@ -336,9 +336,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
{{#java8}}
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/java8}}
{{/dateLibrary_java8}}

import {{invokerPackage}}.auth.Authentication;
{{#hasHttpBasicMethods}}
Expand All @@ -86,7 +86,7 @@ import {{invokerPackage}}.auth.OAuth;

{{>generatedAnnotation}}
@Component("{{invokerPackage}}.ApiClient")
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_java8}} {
public enum CollectionFormat {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
Expand Down Expand Up @@ -407,9 +407,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate( (Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection<?>) param) {
if(b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;

{{#java8}}
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/java8}}
{{/dateLibrary_java8}}
import java.text.DateFormat;
import java.util.*;
import java.util.function.Consumer;
Expand All @@ -45,7 +45,7 @@ import java.util.regex.Pattern;
import static java.util.stream.Collectors.toMap;

{{>generatedAnnotation}}
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_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);
Expand Down Expand Up @@ -298,9 +298,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for (Object o : (Collection) param) {
if (b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
{{#java8}}
{{#dateLibrary_java8}}
import java.time.OffsetDateTime;
{{/java8}}
{{/dateLibrary_java8}}

import {{invokerPackage}}.auth.Authentication;
import {{invokerPackage}}.auth.HttpBasicAuth;
Expand All @@ -72,7 +72,7 @@ import {{invokerPackage}}.auth.OAuth;
{{/hasOAuthMethods}}

{{>generatedAnnotation}}
public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
public class ApiClient{{#dateLibrary_java8}} extends JavaTimeFormatter{{/dateLibrary_java8}} {
public enum CollectionFormat {
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
Expand Down Expand Up @@ -357,9 +357,9 @@ public class ApiClient{{#java8}} extends JavaTimeFormatter{{/java8}} {
return "";
} else if (param instanceof Date) {
return formatDate( (Date) param);
} {{#java8}}else if (param instanceof OffsetDateTime) {
} {{#dateLibrary_java8}}else if (param instanceof OffsetDateTime) {
return formatOffsetDateTime((OffsetDateTime) param);
} {{/java8}}else if (param instanceof Collection) {
} {{/dateLibrary_java8}}else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection<?>) param) {
if(b.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ 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
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/java/vertx/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ public class Example {
String string = "string_example"; // String | None
AsyncFile binary = new AsyncFile(); // AsyncFile | None
LocalDate date = new LocalDate(); // LocalDate | None
OffsetDateTime dateTime = OffsetDateTime.now(); // OffsetDateTime | None
LocalDateTime dateTime = new LocalDateTime(); // LocalDateTime | None
String password = "password_example"; // String | None
String paramCallback = "paramCallback_example"; // String | None
try {
Expand Down Expand Up @@ -611,7 +611,7 @@ Name | Type | Description | Notes
**string** | **String**| None | [optional]
**binary** | **AsyncFile**| None | [optional]
**date** | **LocalDate**| None | [optional]
**dateTime** | **OffsetDateTime**| None | [optional]
**dateTime** | **LocalDateTime**| None | [optional]
**password** | **String**| None | [optional]
**paramCallback** | **String**| None | [optional]

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/vertx/docs/FormatTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Name | Type | Description | Notes
**_byte** | **byte[]** | |
**binary** | **AsyncFile** | | [optional]
**date** | **LocalDate** | |
**dateTime** | **OffsetDateTime** | | [optional]
**dateTime** | **LocalDateTime** | | [optional]
**uuid** | **UUID** | | [optional]
**password** | **String** | |
**bigDecimal** | **BigDecimal** | | [optional]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**uuid** | **UUID** | | [optional]
**dateTime** | **OffsetDateTime** | | [optional]
**dateTime** | **LocalDateTime** | | [optional]
**map** | [**Map&lt;String, Animal&gt;**](Animal.md) | | [optional]


Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/vertx/docs/Order.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Name | Type | Description | Notes
**id** | **Long** | | [optional]
**petId** | **Long** | | [optional]
**quantity** | **Integer** | | [optional]
**shipDate** | **OffsetDateTime** | | [optional]
**shipDate** | **LocalDateTime** | | [optional]
**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional]
**complete** | **Boolean** | | [optional]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand All @@ -39,7 +38,7 @@
import static java.util.stream.Collectors.toMap;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen")
public class ApiClient extends JavaTimeFormatter {
public class ApiClient {

private static final Pattern CONTENT_DISPOSITION_PATTERN = Pattern.compile("filename=['\"]?([^'\"\\s]+)['\"]?");
private static final OpenOptions FILE_DOWNLOAD_OPTIONS = new OpenOptions().setCreate(true).setTruncateExisting(true);
Expand Down Expand Up @@ -288,8 +287,6 @@ 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) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.openapitools.client.model.Client;
import org.openapitools.client.model.FileSchemaTestClass;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.LocalDateTime;
import org.openapitools.client.model.OuterComposite;
import org.openapitools.client.model.User;
import org.openapitools.client.model.XmlItem;
Expand Down Expand Up @@ -50,9 +50,9 @@ public interface FakeApi {

void testClientModel(Client body, ApiClient.AuthInfo authInfo, Handler<AsyncResult<Client>> handler);

void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, AsyncFile binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, Handler<AsyncResult<Void>> handler);
void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, AsyncFile binary, LocalDate date, LocalDateTime dateTime, String password, String paramCallback, Handler<AsyncResult<Void>> handler);

void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, AsyncFile binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback, ApiClient.AuthInfo authInfo, Handler<AsyncResult<Void>> handler);
void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, AsyncFile binary, LocalDate date, LocalDateTime dateTime, String password, String paramCallback, ApiClient.AuthInfo authInfo, Handler<AsyncResult<Void>> handler);

void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString, Handler<AsyncResult<Void>> handler);

Expand Down
Loading

0 comments on commit 03d31bf

Please sign in to comment.