Skip to content

Commit a82475e

Browse files
authored
Fix java rest client's ApiClient constructors to make sure objectMapper parameter is used in the client (#19667) (#19795)
1 parent 7cf84e2 commit a82475e

File tree

7 files changed

+56
-77
lines changed
  • modules/openapi-generator/src/main/resources/Java/libraries/restclient
  • samples/client
    • echo_api/java/restclient/src/main/java/org/openapitools/client
    • others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client
    • petstore/java
      • restclient/src/main/java/org/openapitools/client
      • restclient-nullable-arrays/src/main/java/org/openapitools/client
      • restclient-swagger2/src/main/java/org/openapitools/client
      • restclient-useSingleRequestParameter/src/main/java/org/openapitools/client

7 files changed

+56
-77
lines changed

modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache

+8-11
Original file line numberDiff line numberDiff line change
@@ -87,29 +87,26 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
8787

8888

8989
public ApiClient() {
90-
this.dateFormat = createDefaultDateFormat();
91-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
92-
this.restClient = buildRestClient(this.objectMapper);
93-
this.init();
90+
this(null);
9491
}
9592

9693
public ApiClient(RestClient restClient) {
97-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
94+
this(restClient, createDefaultDateFormat());
9895
}
9996

10097
public ApiClient(ObjectMapper mapper, DateFormat format) {
101-
this(buildRestClient(mapper.copy()), format);
98+
this(null, mapper, format);
10299
}
103100

104101
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
105-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
102+
this.objectMapper = mapper.copy();
103+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
104+
this.dateFormat = format;
105+
this.init();
106106
}
107107

108108
private ApiClient(RestClient restClient, DateFormat format) {
109-
this.restClient = restClient;
110-
this.dateFormat = format;
111-
this.objectMapper = createDefaultObjectMapper(format);
112-
this.init();
109+
this(restClient, createDefaultObjectMapper(format), format);
113110
}
114111

115112
public static DateFormat createDefaultDateFormat() {

samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,26 @@ private String collectionToString(Collection<?> collection) {
8484

8585

8686
public ApiClient() {
87-
this.dateFormat = createDefaultDateFormat();
88-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
89-
this.restClient = buildRestClient(this.objectMapper);
90-
this.init();
87+
this(null);
9188
}
9289

9390
public ApiClient(RestClient restClient) {
94-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
91+
this(restClient, createDefaultDateFormat());
9592
}
9693

9794
public ApiClient(ObjectMapper mapper, DateFormat format) {
98-
this(buildRestClient(mapper.copy()), format);
95+
this(null, mapper, format);
9996
}
10097

10198
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
102-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
99+
this.objectMapper = mapper.copy();
100+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
101+
this.dateFormat = format;
102+
this.init();
103103
}
104104

105105
private ApiClient(RestClient restClient, DateFormat format) {
106-
this.restClient = restClient;
107-
this.dateFormat = format;
108-
this.objectMapper = createDefaultObjectMapper(format);
109-
this.init();
106+
this(restClient, createDefaultObjectMapper(format), format);
110107
}
111108

112109
public static DateFormat createDefaultDateFormat() {

samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,26 @@ private String collectionToString(Collection<?> collection) {
8484

8585

8686
public ApiClient() {
87-
this.dateFormat = createDefaultDateFormat();
88-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
89-
this.restClient = buildRestClient(this.objectMapper);
90-
this.init();
87+
this(null);
9188
}
9289

9390
public ApiClient(RestClient restClient) {
94-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
91+
this(restClient, createDefaultDateFormat());
9592
}
9693

9794
public ApiClient(ObjectMapper mapper, DateFormat format) {
98-
this(buildRestClient(mapper.copy()), format);
95+
this(null, mapper, format);
9996
}
10097

10198
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
102-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
99+
this.objectMapper = mapper.copy();
100+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
101+
this.dateFormat = format;
102+
this.init();
103103
}
104104

105105
private ApiClient(RestClient restClient, DateFormat format) {
106-
this.restClient = restClient;
107-
this.dateFormat = format;
108-
this.objectMapper = createDefaultObjectMapper(format);
109-
this.init();
106+
this(restClient, createDefaultObjectMapper(format), format);
110107
}
111108

112109
public static DateFormat createDefaultDateFormat() {

samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -84,29 +84,26 @@ private String collectionToString(Collection<?> collection) {
8484

8585

8686
public ApiClient() {
87-
this.dateFormat = createDefaultDateFormat();
88-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
89-
this.restClient = buildRestClient(this.objectMapper);
90-
this.init();
87+
this(null);
9188
}
9289

9390
public ApiClient(RestClient restClient) {
94-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
91+
this(restClient, createDefaultDateFormat());
9592
}
9693

9794
public ApiClient(ObjectMapper mapper, DateFormat format) {
98-
this(buildRestClient(mapper.copy()), format);
95+
this(null, mapper, format);
9996
}
10097

10198
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
102-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
99+
this.objectMapper = mapper.copy();
100+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
101+
this.dateFormat = format;
102+
this.init();
103103
}
104104

105105
private ApiClient(RestClient restClient, DateFormat format) {
106-
this.restClient = restClient;
107-
this.dateFormat = format;
108-
this.objectMapper = createDefaultObjectMapper(format);
109-
this.init();
106+
this(restClient, createDefaultObjectMapper(format), format);
110107
}
111108

112109
public static DateFormat createDefaultDateFormat() {

samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,26 @@ private String collectionToString(Collection<?> collection) {
8585

8686

8787
public ApiClient() {
88-
this.dateFormat = createDefaultDateFormat();
89-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
90-
this.restClient = buildRestClient(this.objectMapper);
91-
this.init();
88+
this(null);
9289
}
9390

9491
public ApiClient(RestClient restClient) {
95-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
92+
this(restClient, createDefaultDateFormat());
9693
}
9794

9895
public ApiClient(ObjectMapper mapper, DateFormat format) {
99-
this(buildRestClient(mapper.copy()), format);
96+
this(null, mapper, format);
10097
}
10198

10299
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
103-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
100+
this.objectMapper = mapper.copy();
101+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
102+
this.dateFormat = format;
103+
this.init();
104104
}
105105

106106
private ApiClient(RestClient restClient, DateFormat format) {
107-
this.restClient = restClient;
108-
this.dateFormat = format;
109-
this.objectMapper = createDefaultObjectMapper(format);
110-
this.init();
107+
this(restClient, createDefaultObjectMapper(format), format);
111108
}
112109

113110
public static DateFormat createDefaultDateFormat() {

samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,26 @@ private String collectionToString(Collection<?> collection) {
8585

8686

8787
public ApiClient() {
88-
this.dateFormat = createDefaultDateFormat();
89-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
90-
this.restClient = buildRestClient(this.objectMapper);
91-
this.init();
88+
this(null);
9289
}
9390

9491
public ApiClient(RestClient restClient) {
95-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
92+
this(restClient, createDefaultDateFormat());
9693
}
9794

9895
public ApiClient(ObjectMapper mapper, DateFormat format) {
99-
this(buildRestClient(mapper.copy()), format);
96+
this(null, mapper, format);
10097
}
10198

10299
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
103-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
100+
this.objectMapper = mapper.copy();
101+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
102+
this.dateFormat = format;
103+
this.init();
104104
}
105105

106106
private ApiClient(RestClient restClient, DateFormat format) {
107-
this.restClient = restClient;
108-
this.dateFormat = format;
109-
this.objectMapper = createDefaultObjectMapper(format);
110-
this.init();
107+
this(restClient, createDefaultObjectMapper(format), format);
111108
}
112109

113110
public static DateFormat createDefaultDateFormat() {

samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,26 @@ private String collectionToString(Collection<?> collection) {
8585

8686

8787
public ApiClient() {
88-
this.dateFormat = createDefaultDateFormat();
89-
this.objectMapper = createDefaultObjectMapper(this.dateFormat);
90-
this.restClient = buildRestClient(this.objectMapper);
91-
this.init();
88+
this(null);
9289
}
9390

9491
public ApiClient(RestClient restClient) {
95-
this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat());
92+
this(restClient, createDefaultDateFormat());
9693
}
9794

9895
public ApiClient(ObjectMapper mapper, DateFormat format) {
99-
this(buildRestClient(mapper.copy()), format);
96+
this(null, mapper, format);
10097
}
10198

10299
public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) {
103-
this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format);
100+
this.objectMapper = mapper.copy();
101+
this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper));
102+
this.dateFormat = format;
103+
this.init();
104104
}
105105

106106
private ApiClient(RestClient restClient, DateFormat format) {
107-
this.restClient = restClient;
108-
this.dateFormat = format;
109-
this.objectMapper = createDefaultObjectMapper(format);
110-
this.init();
107+
this(restClient, createDefaultObjectMapper(format), format);
111108
}
112109

113110
public static DateFormat createDefaultDateFormat() {

0 commit comments

Comments
 (0)