mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-10 22:22:52 +00:00
[Java] Make Java ApiClient extendable (#21251)
* Make all Java ApiClients in templates extendable * Make all Java ApiClients in samples extendable * Fix compilation of enum constructor * Fix compilation of enum constructor in templates
This commit is contained in:
@@ -83,9 +83,9 @@ import org.openapitools.client.auth.HttpBearerAuth;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.14.0-SNAPSHOT")
|
||||
public class ApiClient extends JavaTimeFormatter {
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
private String basePath = "http://localhost:3000";
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
protected String basePath = "http://localhost:3000";
|
||||
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"http://localhost:3000",
|
||||
@@ -95,22 +95,22 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
));
|
||||
protected Integer serverIndex = 0;
|
||||
protected Map<String, String> serverVariables = null;
|
||||
private boolean debugging = false;
|
||||
private int connectionTimeout = 0;
|
||||
protected boolean debugging = false;
|
||||
protected int connectionTimeout = 0;
|
||||
|
||||
private CloseableHttpClient httpClient;
|
||||
private ObjectMapper objectMapper;
|
||||
protected CloseableHttpClient httpClient;
|
||||
protected ObjectMapper objectMapper;
|
||||
protected String tempFolderPath = null;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
private Map<Long, Integer> lastStatusCodeByThread = new ConcurrentHashMap<>();
|
||||
private Map<Long, Map<String, List<String>>> lastResponseHeadersByThread = new ConcurrentHashMap<>();
|
||||
protected Map<Long, Integer> lastStatusCodeByThread = new ConcurrentHashMap<>();
|
||||
protected Map<Long, Map<String, List<String>>> lastResponseHeadersByThread = new ConcurrentHashMap<>();
|
||||
|
||||
private DateFormat dateFormat;
|
||||
protected DateFormat dateFormat;
|
||||
|
||||
// Methods that can have a request body
|
||||
private static List<String> bodyMethods = Arrays.asList("POST", "PUT", "DELETE", "PATCH");
|
||||
protected static List<String> bodyMethods = Arrays.asList("POST", "PUT", "DELETE", "PATCH");
|
||||
|
||||
public ApiClient(CloseableHttpClient httpClient) {
|
||||
objectMapper = new ObjectMapper();
|
||||
@@ -675,7 +675,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
/**
|
||||
* Parse content type object from header value
|
||||
*/
|
||||
private ContentType getContentType(String headerValue) throws ApiException {
|
||||
protected ContentType getContentType(String headerValue) throws ApiException {
|
||||
try {
|
||||
return ContentType.parse(headerValue);
|
||||
} catch (UnsupportedCharsetException e) {
|
||||
@@ -686,7 +686,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
/**
|
||||
* Get content type of a response or null if one was not provided
|
||||
*/
|
||||
private String getResponseMimeType(HttpResponse response) throws ApiException {
|
||||
protected String getResponseMimeType(HttpResponse response) throws ApiException {
|
||||
Header contentTypeHeader = response.getFirstHeader("Content-Type");
|
||||
if (contentTypeHeader != null) {
|
||||
return getContentType(contentTypeHeader.getValue()).getMimeType();
|
||||
@@ -795,7 +795,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
private File downloadFileFromResponse(CloseableHttpResponse response) throws IOException {
|
||||
protected File downloadFileFromResponse(CloseableHttpResponse response) throws IOException {
|
||||
Header contentDispositionHeader = response.getFirstHeader("Content-Disposition");
|
||||
String contentDisposition = contentDispositionHeader == null ? null : contentDispositionHeader.getValue();
|
||||
File file = prepareDownloadFile(contentDisposition);
|
||||
@@ -866,7 +866,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param urlQueryDeepObject URL query string of the deep object parameters
|
||||
* @return The full URL
|
||||
*/
|
||||
private String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject) {
|
||||
protected String buildUrl(String path, List<Pair> queryParams, List<Pair> collectionQueryParams, String urlQueryDeepObject) {
|
||||
String baseURL = getBaseURL();
|
||||
|
||||
final StringBuilder url = new StringBuilder();
|
||||
@@ -1045,7 +1045,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param headerParams Header parameters
|
||||
* @param cookieParams Cookie parameters
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
|
||||
@@ -33,13 +33,13 @@ import org.openapitools.client.auth.ApiKeyAuth;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.14.0-SNAPSHOT")
|
||||
public class ApiClient {
|
||||
private static final Logger log = Logger.getLogger(ApiClient.class.getName());
|
||||
protected static final Logger log = Logger.getLogger(ApiClient.class.getName());
|
||||
|
||||
public interface Api {}
|
||||
|
||||
private String basePath = "http://localhost:3000";
|
||||
private Map<String, RequestInterceptor> apiAuthorizations;
|
||||
private Feign.Builder feignBuilder;
|
||||
protected String basePath = "http://localhost:3000";
|
||||
protected Map<String, RequestInterceptor> apiAuthorizations;
|
||||
protected Feign.Builder feignBuilder;
|
||||
|
||||
public ApiClient() {
|
||||
apiAuthorizations = new LinkedHashMap<String, RequestInterceptor>();
|
||||
@@ -219,7 +219,7 @@ public class ApiClient {
|
||||
feignBuilder.requestInterceptor(authorization);
|
||||
}
|
||||
|
||||
private <T extends RequestInterceptor> T getAuthorization(Class<T> type) {
|
||||
protected <T extends RequestInterceptor> T getAuthorization(Class<T> type) {
|
||||
return (T) apiAuthorizations.values()
|
||||
.stream()
|
||||
.filter(requestInterceptor -> type.isAssignableFrom(requestInterceptor.getClass()))
|
||||
|
||||
@@ -54,17 +54,17 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.14.0-SNAPSHOT")
|
||||
public class ApiClient {
|
||||
|
||||
private HttpClient.Builder builder;
|
||||
private ObjectMapper mapper;
|
||||
private String scheme;
|
||||
private String host;
|
||||
private int port;
|
||||
private String basePath;
|
||||
private Consumer<HttpRequest.Builder> interceptor;
|
||||
private Consumer<HttpResponse<InputStream>> responseInterceptor;
|
||||
private Consumer<HttpResponse<String>> asyncResponseInterceptor;
|
||||
private Duration readTimeout;
|
||||
private Duration connectTimeout;
|
||||
protected HttpClient.Builder builder;
|
||||
protected ObjectMapper mapper;
|
||||
protected String scheme;
|
||||
protected String host;
|
||||
protected int port;
|
||||
protected String basePath;
|
||||
protected Consumer<HttpRequest.Builder> interceptor;
|
||||
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
|
||||
protected Consumer<HttpResponse<String>> asyncResponseInterceptor;
|
||||
protected Duration readTimeout;
|
||||
protected Duration connectTimeout;
|
||||
|
||||
public static String valueToString(Object value) {
|
||||
if (value == null) {
|
||||
@@ -207,7 +207,7 @@ public class ApiClient {
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private String getDefaultBaseUri() {
|
||||
protected String getDefaultBaseUri() {
|
||||
return "http://localhost:3000";
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ import org.openapitools.client.auth.OAuthFlow;
|
||||
*/
|
||||
public class ApiClient {
|
||||
|
||||
private String basePath = "http://petstore.swagger.io/v2";
|
||||
protected String basePath = "http://petstore.swagger.io/v2";
|
||||
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"http://petstore.swagger.io/v2",
|
||||
@@ -76,26 +76,26 @@ public class ApiClient {
|
||||
));
|
||||
protected Integer serverIndex = 0;
|
||||
protected Map<String, String> serverVariables = null;
|
||||
private boolean debugging = false;
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
private String tempFolderPath = null;
|
||||
protected boolean debugging = false;
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
protected String tempFolderPath = null;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat datetimeFormat;
|
||||
private boolean lenientDatetimeFormat;
|
||||
private int dateLength;
|
||||
protected DateFormat dateFormat;
|
||||
protected DateFormat datetimeFormat;
|
||||
protected boolean lenientDatetimeFormat;
|
||||
protected int dateLength;
|
||||
|
||||
private InputStream sslCaCert;
|
||||
private boolean verifyingSsl;
|
||||
private KeyManager[] keyManagers;
|
||||
protected InputStream sslCaCert;
|
||||
protected boolean verifyingSsl;
|
||||
protected KeyManager[] keyManagers;
|
||||
|
||||
private OkHttpClient httpClient;
|
||||
private JSON json;
|
||||
protected OkHttpClient httpClient;
|
||||
protected JSON json;
|
||||
|
||||
private HttpLoggingInterceptor loggingInterceptor;
|
||||
protected HttpLoggingInterceptor loggingInterceptor;
|
||||
|
||||
/**
|
||||
* Basic constructor for ApiClient
|
||||
@@ -195,11 +195,11 @@ public class ApiClient {
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
private void initHttpClient() {
|
||||
protected void initHttpClient() {
|
||||
initHttpClient(Collections.<Interceptor>emptyList());
|
||||
}
|
||||
|
||||
private void initHttpClient(List<Interceptor> interceptors) {
|
||||
protected void initHttpClient(List<Interceptor> interceptors) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.addNetworkInterceptor(getProgressInterceptor());
|
||||
for (Interceptor interceptor: interceptors) {
|
||||
@@ -209,7 +209,7 @@ public class ApiClient {
|
||||
httpClient = builder.build();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
protected void init() {
|
||||
verifyingSsl = true;
|
||||
|
||||
json = new JSON();
|
||||
@@ -1530,7 +1530,7 @@ public class ApiClient {
|
||||
* @param key The key of the Header element
|
||||
* @param file The file to add to the Header
|
||||
*/
|
||||
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||
@@ -1543,7 +1543,7 @@ public class ApiClient {
|
||||
* @param key The key of the Header element
|
||||
* @param obj The complex object to add to the Header
|
||||
*/
|
||||
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
|
||||
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
|
||||
RequestBody requestBody;
|
||||
if (obj instanceof String) {
|
||||
requestBody = RequestBody.create((String) obj, MediaType.parse("text/plain"));
|
||||
@@ -1565,7 +1565,7 @@ public class ApiClient {
|
||||
* Get network interceptor to add it to the httpClient to track download progress for
|
||||
* async requests.
|
||||
*/
|
||||
private Interceptor getProgressInterceptor() {
|
||||
protected Interceptor getProgressInterceptor() {
|
||||
return new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
@@ -1586,7 +1586,7 @@ public class ApiClient {
|
||||
* Apply SSL related settings to httpClient according to the current values of
|
||||
* verifyingSsl and sslCaCert.
|
||||
*/
|
||||
private void applySslSettings() {
|
||||
protected void applySslSettings() {
|
||||
try {
|
||||
TrustManager[] trustManagers;
|
||||
HostnameVerifier hostnameVerifier;
|
||||
@@ -1648,7 +1648,7 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
|
||||
protected KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
|
||||
try {
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, password);
|
||||
@@ -1665,7 +1665,7 @@ public class ApiClient {
|
||||
* @return The string representation of the HTTP request body
|
||||
* @throws org.openapitools.client.ApiException If fail to serialize the request body object into a string
|
||||
*/
|
||||
private String requestBodyToString(RequestBody requestBody) throws ApiException {
|
||||
protected String requestBodyToString(RequestBody requestBody) throws ApiException {
|
||||
if (requestBody != null) {
|
||||
try {
|
||||
final Buffer buffer = new Buffer();
|
||||
|
||||
@@ -61,7 +61,7 @@ import org.openapitools.client.auth.ApiKeyAuth;
|
||||
*/
|
||||
public class ApiClient {
|
||||
|
||||
private String basePath = "http://localhost:3000";
|
||||
protected String basePath = "http://localhost:3000";
|
||||
protected List<ServerConfiguration> servers = new ArrayList<ServerConfiguration>(Arrays.asList(
|
||||
new ServerConfiguration(
|
||||
"http://localhost:3000",
|
||||
@@ -71,26 +71,26 @@ public class ApiClient {
|
||||
));
|
||||
protected Integer serverIndex = 0;
|
||||
protected Map<String, String> serverVariables = null;
|
||||
private boolean debugging = false;
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
private String tempFolderPath = null;
|
||||
protected boolean debugging = false;
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
protected String tempFolderPath = null;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat datetimeFormat;
|
||||
private boolean lenientDatetimeFormat;
|
||||
private int dateLength;
|
||||
protected DateFormat dateFormat;
|
||||
protected DateFormat datetimeFormat;
|
||||
protected boolean lenientDatetimeFormat;
|
||||
protected int dateLength;
|
||||
|
||||
private InputStream sslCaCert;
|
||||
private boolean verifyingSsl;
|
||||
private KeyManager[] keyManagers;
|
||||
protected InputStream sslCaCert;
|
||||
protected boolean verifyingSsl;
|
||||
protected KeyManager[] keyManagers;
|
||||
|
||||
private OkHttpClient httpClient;
|
||||
private JSON json;
|
||||
protected OkHttpClient httpClient;
|
||||
protected JSON json;
|
||||
|
||||
private HttpLoggingInterceptor loggingInterceptor;
|
||||
protected HttpLoggingInterceptor loggingInterceptor;
|
||||
|
||||
/**
|
||||
* Basic constructor for ApiClient
|
||||
@@ -123,11 +123,11 @@ public class ApiClient {
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
private void initHttpClient() {
|
||||
protected void initHttpClient() {
|
||||
initHttpClient(Collections.<Interceptor>emptyList());
|
||||
}
|
||||
|
||||
private void initHttpClient(List<Interceptor> interceptors) {
|
||||
protected void initHttpClient(List<Interceptor> interceptors) {
|
||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||
builder.addNetworkInterceptor(getProgressInterceptor());
|
||||
for (Interceptor interceptor: interceptors) {
|
||||
@@ -137,7 +137,7 @@ public class ApiClient {
|
||||
httpClient = builder.build();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
protected void init() {
|
||||
verifyingSsl = true;
|
||||
|
||||
json = new JSON();
|
||||
@@ -1460,7 +1460,7 @@ public class ApiClient {
|
||||
* @param key The key of the Header element
|
||||
* @param file The file to add to the Header
|
||||
*/
|
||||
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, File file) {
|
||||
Headers partHeaders = Headers.of("Content-Disposition", "form-data; name=\"" + key + "\"; filename=\"" + file.getName() + "\"");
|
||||
MediaType mediaType = MediaType.parse(guessContentTypeFromFile(file));
|
||||
mpBuilder.addPart(partHeaders, RequestBody.create(file, mediaType));
|
||||
@@ -1473,7 +1473,7 @@ public class ApiClient {
|
||||
* @param key The key of the Header element
|
||||
* @param obj The complex object to add to the Header
|
||||
*/
|
||||
private void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
|
||||
protected void addPartToMultiPartBuilder(MultipartBody.Builder mpBuilder, String key, Object obj) {
|
||||
RequestBody requestBody;
|
||||
if (obj instanceof String) {
|
||||
requestBody = RequestBody.create((String) obj, MediaType.parse("text/plain"));
|
||||
@@ -1495,7 +1495,7 @@ public class ApiClient {
|
||||
* Get network interceptor to add it to the httpClient to track download progress for
|
||||
* async requests.
|
||||
*/
|
||||
private Interceptor getProgressInterceptor() {
|
||||
protected Interceptor getProgressInterceptor() {
|
||||
return new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Interceptor.Chain chain) throws IOException {
|
||||
@@ -1516,7 +1516,7 @@ public class ApiClient {
|
||||
* Apply SSL related settings to httpClient according to the current values of
|
||||
* verifyingSsl and sslCaCert.
|
||||
*/
|
||||
private void applySslSettings() {
|
||||
protected void applySslSettings() {
|
||||
try {
|
||||
TrustManager[] trustManagers;
|
||||
HostnameVerifier hostnameVerifier;
|
||||
@@ -1578,7 +1578,7 @@ public class ApiClient {
|
||||
}
|
||||
}
|
||||
|
||||
private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
|
||||
protected KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityException {
|
||||
try {
|
||||
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
keyStore.load(null, password);
|
||||
@@ -1595,7 +1595,7 @@ public class ApiClient {
|
||||
* @return The string representation of the HTTP request body
|
||||
* @throws org.openapitools.client.ApiException If fail to serialize the request body object into a string
|
||||
*/
|
||||
private String requestBodyToString(RequestBody requestBody) throws ApiException {
|
||||
protected String requestBodyToString(RequestBody requestBody) throws ApiException {
|
||||
if (requestBody != null) {
|
||||
try {
|
||||
final Buffer buffer = new Buffer();
|
||||
|
||||
@@ -62,26 +62,26 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
public enum CollectionFormat {
|
||||
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
|
||||
|
||||
private final String separator;
|
||||
protected final String separator;
|
||||
CollectionFormat(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
private String collectionToString(Collection<?> collection) {
|
||||
protected String collectionToString(Collection<?> collection) {
|
||||
return StringUtils.collectionToDelimitedString(collection, separator);
|
||||
}
|
||||
}
|
||||
|
||||
private final HttpHeaders defaultHeaders = new HttpHeaders();
|
||||
private final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();
|
||||
protected final HttpHeaders defaultHeaders = new HttpHeaders();
|
||||
protected final MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<>();
|
||||
|
||||
private String basePath = "http://localhost:3000";
|
||||
protected String basePath = "http://localhost:3000";
|
||||
|
||||
private final RestClient restClient;
|
||||
private final DateFormat dateFormat;
|
||||
private final ObjectMapper objectMapper;
|
||||
protected final RestClient restClient;
|
||||
protected final DateFormat dateFormat;
|
||||
protected final ObjectMapper objectMapper;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
|
||||
public ApiClient() {
|
||||
@@ -103,7 +103,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
this.init();
|
||||
}
|
||||
|
||||
private ApiClient(RestClient restClient, DateFormat format) {
|
||||
protected ApiClient(RestClient restClient, DateFormat format) {
|
||||
this(restClient, createDefaultObjectMapper(format), format);
|
||||
}
|
||||
|
||||
@@ -580,7 +580,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param uriParams The path parameters
|
||||
* return templatized query string
|
||||
*/
|
||||
private String generateQueryUri(MultiValueMap<String, String> queryParams, Map<String, Object> uriParams) {
|
||||
protected String generateQueryUri(MultiValueMap<String, String> queryParams, Map<String, Object> uriParams) {
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
queryParams.forEach((name, values) -> {
|
||||
if (CollectionUtils.isEmpty(values)) {
|
||||
@@ -606,7 +606,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
return queryBuilder.toString();
|
||||
}
|
||||
|
||||
private RestClient.RequestBodySpec prepareRequest(String path, HttpMethod method, Map<String, Object> pathParams,
|
||||
protected RestClient.RequestBodySpec prepareRequest(String path, HttpMethod method, Map<String, Object> pathParams,
|
||||
MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams,
|
||||
MultiValueMap<String, String> cookieParams, MultiValueMap<String, Object> formParams, List<MediaType> accept,
|
||||
MediaType contentType, String[] authNames) {
|
||||
@@ -682,7 +682,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param cookies map all cookies
|
||||
* @return header string for cookies.
|
||||
*/
|
||||
private String buildCookieHeader(MultiValueMap<String, String> cookies) {
|
||||
protected String buildCookieHeader(MultiValueMap<String, String> cookies) {
|
||||
final StringBuilder cookieValue = new StringBuilder();
|
||||
String delimiter = "";
|
||||
for (final Map.Entry<String, List<String>> entry : cookies.entrySet()) {
|
||||
|
||||
@@ -62,21 +62,21 @@ import org.openapitools.client.auth.ApiKeyAuth;
|
||||
|
||||
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.14.0-SNAPSHOT")
|
||||
public class ApiClient extends JavaTimeFormatter {
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
private String basePath = "http://localhost:3000";
|
||||
private boolean debugging = false;
|
||||
protected Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
protected Map<String, String> defaultCookieMap = new HashMap<String, String>();
|
||||
protected String basePath = "http://localhost:3000";
|
||||
protected boolean debugging = false;
|
||||
|
||||
private Client httpClient;
|
||||
private JSON json;
|
||||
private String tempFolderPath = null;
|
||||
protected Client httpClient;
|
||||
protected JSON json;
|
||||
protected String tempFolderPath = null;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
private int statusCode;
|
||||
private Map<String, List<String>> responseHeaders;
|
||||
protected int statusCode;
|
||||
protected Map<String, List<String>> responseHeaders;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
protected DateFormat dateFormat;
|
||||
|
||||
public ApiClient() {
|
||||
json = new JSON();
|
||||
@@ -695,7 +695,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
private Response invoke(Invocation.Builder invocationBuilder, String method, Entity<?> entity) throws ApiException {
|
||||
protected Response invoke(Invocation.Builder invocationBuilder, String method, Entity<?> entity) throws ApiException {
|
||||
Response response = null;
|
||||
|
||||
if ("GET".equals(method)) {
|
||||
@@ -724,7 +724,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
/**
|
||||
* Build the Client used to make HTTP requests.
|
||||
*/
|
||||
private Client buildHttpClient(boolean debugging) {
|
||||
protected Client buildHttpClient(boolean debugging) {
|
||||
final ClientConfiguration clientConfig = new ClientConfiguration(ResteasyProviderFactory.getInstance());
|
||||
clientConfig.register(json);
|
||||
if(debugging){
|
||||
@@ -732,7 +732,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
}
|
||||
return ClientBuilder.newClient(clientConfig);
|
||||
}
|
||||
private Map<String, List<String>> buildResponseHeaders(Response response) {
|
||||
protected Map<String, List<String>> buildResponseHeaders(Response response) {
|
||||
Map<String, List<String>> responseHeaders = new HashMap<String, List<String>>();
|
||||
for (Entry<String, List<Object>> entry: response.getHeaders().entrySet()) {
|
||||
List<Object> values = entry.getValue();
|
||||
@@ -750,7 +750,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
protected void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams, Map<String, String> cookieParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
|
||||
@@ -78,33 +78,33 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
public enum CollectionFormat {
|
||||
CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null);
|
||||
|
||||
private final String separator;
|
||||
protected final String separator;
|
||||
|
||||
private CollectionFormat(String separator) {
|
||||
CollectionFormat(String separator) {
|
||||
this.separator = separator;
|
||||
}
|
||||
|
||||
private String collectionToString(Collection<?> collection) {
|
||||
protected String collectionToString(Collection<?> collection) {
|
||||
return StringUtils.collectionToDelimitedString(collection, separator);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean debugging = false;
|
||||
protected boolean debugging = false;
|
||||
|
||||
private HttpHeaders defaultHeaders = new HttpHeaders();
|
||||
private MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<String, String>();
|
||||
protected HttpHeaders defaultHeaders = new HttpHeaders();
|
||||
protected MultiValueMap<String, String> defaultCookies = new LinkedMultiValueMap<String, String>();
|
||||
|
||||
private int maxAttemptsForRetry = 1;
|
||||
protected int maxAttemptsForRetry = 1;
|
||||
|
||||
private long waitTimeMillis = 10;
|
||||
protected long waitTimeMillis = 10;
|
||||
|
||||
private String basePath = "http://localhost:3000";
|
||||
protected String basePath = "http://localhost:3000";
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
protected RestTemplate restTemplate;
|
||||
|
||||
private Map<String, Authentication> authentications;
|
||||
protected Map<String, Authentication> authentications;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
protected DateFormat dateFormat;
|
||||
|
||||
public ApiClient() {
|
||||
this.restTemplate = buildRestTemplate();
|
||||
@@ -770,7 +770,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
* @param cookies map all cookies
|
||||
* @return header string for cookies.
|
||||
*/
|
||||
private String buildCookieHeader(MultiValueMap<String, String> cookies) {
|
||||
protected String buildCookieHeader(MultiValueMap<String, String> cookies) {
|
||||
final StringBuilder cookieValue = new StringBuilder();
|
||||
String delimiter = "";
|
||||
for (final Map.Entry<String, List<String>> entry : cookies.entrySet()) {
|
||||
@@ -814,8 +814,8 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
}
|
||||
}
|
||||
|
||||
private class ApiClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
|
||||
private final Log log = LogFactory.getLog(ApiClientHttpRequestInterceptor.class);
|
||||
protected class ApiClientHttpRequestInterceptor implements ClientHttpRequestInterceptor {
|
||||
protected final Log log = LogFactory.getLog(ApiClientHttpRequestInterceptor.class);
|
||||
|
||||
@Override
|
||||
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
|
||||
@@ -825,21 +825,21 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
return response;
|
||||
}
|
||||
|
||||
private void logRequest(HttpRequest request, byte[] body) throws UnsupportedEncodingException {
|
||||
protected void logRequest(HttpRequest request, byte[] body) throws UnsupportedEncodingException {
|
||||
log.info("URI: " + request.getURI());
|
||||
log.info("HTTP Method: " + request.getMethod());
|
||||
log.info("HTTP Headers: " + headersToString(request.getHeaders()));
|
||||
log.info("Request Body: " + new String(body, StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
private void logResponse(ClientHttpResponse response) throws IOException {
|
||||
protected void logResponse(ClientHttpResponse response) throws IOException {
|
||||
log.info("HTTP Status Code: " + response.getStatusCode().value());
|
||||
log.info("Status Text: " + response.getStatusText());
|
||||
log.info("HTTP Headers: " + headersToString(response.getHeaders()));
|
||||
log.info("Response Body: " + bodyToString(response.getBody()));
|
||||
}
|
||||
|
||||
private String headersToString(HttpHeaders headers) {
|
||||
protected String headersToString(HttpHeaders headers) {
|
||||
if(headers == null || headers.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
@@ -856,7 +856,7 @@ public class ApiClient extends JavaTimeFormatter {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private String bodyToString(InputStream body) throws IOException {
|
||||
protected String bodyToString(InputStream body) throws IOException {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
|
||||
String line = bufferedReader.readLine();
|
||||
|
||||
Reference in New Issue
Block a user