[Java] Add add constructor to BYO OkHttpClient (#6401)

* [Java] Add add constructor to BYO OkHttpClient

* client example

* this client changed too
This commit is contained in:
Jonathan Goldman 2020-06-14 21:35:58 -04:00 committed by GitHub
parent 171337e5f3
commit 1a2097e81d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 0 deletions

View File

@ -102,6 +102,23 @@ public class ApiClient {
authentications = Collections.unmodifiableMap(authentications);
}
/*
* Basic constructor with custom OkHttpClient
*/
public ApiClient(OkHttpClient client) {
init();
httpClient = client;
// Setup authentications (key: authentication name, value: authentication).{{#authMethods}}{{#isBasic}}{{#isBasicBasic}}
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{^isBasicBasic}}
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBasic}}{{/isBasic}}{{#isApiKey}}
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
{{#hasOAuthMethods}}
{{#oauthMethods}}
{{#-first}}

View File

@ -97,6 +97,23 @@ public class ApiClient {
authentications = Collections.unmodifiableMap(authentications);
}
/*
* Basic constructor with custom OkHttpClient
*/
public ApiClient(OkHttpClient client) {
init();
httpClient = client;
// Setup authentications (key: authentication name, value: authentication).
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
/*
* Constructor for ApiClient to support access token retry on 401/403 configured with client ID
*/

View File

@ -97,6 +97,23 @@ public class ApiClient {
authentications = Collections.unmodifiableMap(authentications);
}
/*
* Basic constructor with custom OkHttpClient
*/
public ApiClient(OkHttpClient client) {
init();
httpClient = client;
// Setup authentications (key: authentication name, value: authentication).
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
authentications.put("http_basic_test", new HttpBasicAuth());
authentications.put("petstore_auth", new OAuth());
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);
}
/*
* Constructor for ApiClient to support access token retry on 401/403 configured with client ID
*/