[Java-jersey2] Add new ApiClient constructor with auth objects (#6393)

* Mustache template should use invokerPackage tag to generate import

* Add new constructor for Java ApiClient

* Add constructor with auth map
This commit is contained in:
Sebastien Rosset
2020-05-22 08:54:05 -07:00
committed by GitHub
parent 693e640872
commit 912604f3dc
3 changed files with 131 additions and 13 deletions

View File

@@ -87,7 +87,19 @@ public class ApiClient {
protected DateFormat dateFormat;
/**
* Constructs a new ApiClient with default parameters.
*/
public ApiClient() {
this(null);
}
/**
* Constructs a new ApiClient with the specified authentication parameters.
*
* @param authMap A hash map containing authentication parameters.
*/
public ApiClient(Map<String, Authentication> authMap) {
json = new JSON();
httpClient = buildHttpClient(debugging);
@@ -98,10 +110,39 @@ public class ApiClient {
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap<String, 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(basePath, ""));
Authentication auth = null;
if (authMap != null) {
auth = authMap.get("api_key");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key", auth);
} else {
authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
}
if (authMap != null) {
auth = authMap.get("api_key_query");
}
if (auth instanceof ApiKeyAuth) {
authentications.put("api_key_query", auth);
} else {
authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query"));
}
if (authMap != null) {
auth = authMap.get("http_basic_test");
}
if (auth instanceof HttpBasicAuth) {
authentications.put("http_basic_test", auth);
} else {
authentications.put("http_basic_test", new HttpBasicAuth());
}
if (authMap != null) {
auth = authMap.get("petstore_auth");
}
if (auth instanceof OAuth) {
authentications.put("petstore_auth", auth);
} else {
authentications.put("petstore_auth", new OAuth(basePath, ""));
}
// Prevent the authentications from being modified.
authentications = Collections.unmodifiableMap(authentications);