forked from loafle/openapi-generator-original
[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:
@@ -152,7 +152,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);
|
||||
|
||||
@@ -163,23 +175,47 @@ public class ApiClient {
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();
|
||||
Authentication auth = null;
|
||||
{{#authMethods}}
|
||||
if (authMap != null) {
|
||||
auth = authMap.get("{{name}}");
|
||||
}
|
||||
{{#isBasic}}
|
||||
{{#isBasicBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new HttpBasicAuth());
|
||||
}
|
||||
{{/isBasicBasic}}
|
||||
{{#isBasicBearer}}
|
||||
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
|
||||
if (auth instanceof HttpBearerAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));
|
||||
}
|
||||
{{/isBasicBearer}}
|
||||
{{#isHttpSignature}}
|
||||
authentications.put("{{name}}", new HttpSignatureAuth("{{name}}", null, null));
|
||||
if (auth instanceof HttpSignatureAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", null);
|
||||
}
|
||||
{{/isHttpSignature}}
|
||||
{{/isBasic}}
|
||||
{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));
|
||||
}
|
||||
{{/isApiKey}}
|
||||
{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
|
||||
if (auth instanceof OAuth) {
|
||||
authentications.put("{{name}}", auth);
|
||||
} else {
|
||||
authentications.put("{{name}}", new OAuth(basePath, "{{tokenUrl}}"));
|
||||
}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user