From 71eaa08145e748fa3e14107722e39a257d8ca1fe Mon Sep 17 00:00:00 2001 From: Tomasz Letachowicz Date: Sun, 6 Oct 2024 23:14:14 +0200 Subject: [PATCH] Fix java rest client's ApiClient constructors to make sure objectMapper parameter is used in the client (#19667) --- .../libraries/restclient/ApiClient.mustache | 19 ++++++++----------- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- .../builds/enum-single-value/index.ts | 4 ++-- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- .../org/openapitools/client/ApiClient.java | 19 ++++++++----------- 8 files changed, 58 insertions(+), 79 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache index 8af468cfb4cf..43d97e14f196 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache @@ -87,29 +87,26 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java index cadf8f35e864..2da8eb124cbf 100644 --- a/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/ApiClient.java @@ -84,29 +84,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 490ab1033dfa..3a562ba80e3c 100644 --- a/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/restclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -84,29 +84,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/others/typescript/builds/enum-single-value/index.ts b/samples/client/others/typescript/builds/enum-single-value/index.ts index 791121d1c8dc..c5bc5ff26cc0 100644 --- a/samples/client/others/typescript/builds/enum-single-value/index.ts +++ b/samples/client/others/typescript/builds/enum-single-value/index.ts @@ -2,11 +2,11 @@ export * from "./http/http"; export * from "./auth/auth"; export * from "./models/all"; export { createConfiguration } from "./configuration" -export { Configuration } from "./configuration" +export type { Configuration } from "./configuration" export * from "./apis/exception"; export * from "./servers"; export { RequiredError } from "./apis/baseapi"; -export { PromiseMiddleware as Middleware } from './middleware'; +export type { PromiseMiddleware as Middleware } from './middleware'; export { } from './types/PromiseAPI'; diff --git a/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java index c42a51c9a78e..65ce5d69a8d3 100644 --- a/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java @@ -84,29 +84,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 51ae07b26f24..491296f3f9e0 100644 --- a/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -85,29 +85,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/ApiClient.java index 51ae07b26f24..491296f3f9e0 100644 --- a/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient-useSingleRequestParameter/src/main/java/org/openapitools/client/ApiClient.java @@ -85,29 +85,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() { diff --git a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java index 51ae07b26f24..491296f3f9e0 100644 --- a/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/restclient/src/main/java/org/openapitools/client/ApiClient.java @@ -85,29 +85,26 @@ private String collectionToString(Collection collection) { public ApiClient() { - this.dateFormat = createDefaultDateFormat(); - this.objectMapper = createDefaultObjectMapper(this.dateFormat); - this.restClient = buildRestClient(this.objectMapper); - this.init(); + this(null); } public ApiClient(RestClient restClient) { - this(Optional.ofNullable(restClient).orElseGet(ApiClient::buildRestClient), createDefaultDateFormat()); + this(restClient, createDefaultDateFormat()); } public ApiClient(ObjectMapper mapper, DateFormat format) { - this(buildRestClient(mapper.copy()), format); + this(null, mapper, format); } public ApiClient(RestClient restClient, ObjectMapper mapper, DateFormat format) { - this(Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(mapper.copy())), format); + this.objectMapper = mapper.copy(); + this.restClient = Optional.ofNullable(restClient).orElseGet(() -> buildRestClient(this.objectMapper)); + this.dateFormat = format; + this.init(); } private ApiClient(RestClient restClient, DateFormat format) { - this.restClient = restClient; - this.dateFormat = format; - this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this(restClient, createDefaultObjectMapper(format), format); } public static DateFormat createDefaultDateFormat() {