mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-18 20:27:08 +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:
@@ -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
|
||||
@@ -198,11 +198,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) {
|
||||
@@ -212,7 +212,7 @@ public class ApiClient {
|
||||
httpClient = builder.build();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
protected void init() {
|
||||
verifyingSsl = true;
|
||||
|
||||
json = new JSON();
|
||||
@@ -1533,7 +1533,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));
|
||||
@@ -1546,7 +1546,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"));
|
||||
@@ -1568,7 +1568,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 {
|
||||
@@ -1589,7 +1589,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;
|
||||
@@ -1651,7 +1651,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);
|
||||
@@ -1668,7 +1668,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();
|
||||
|
||||
Reference in New Issue
Block a user