forked from loafle/openapi-generator-original
rollback java template
This commit is contained in:
parent
900f39686d
commit
180d48e89d
@ -40,482 +40,468 @@ import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
|
||||
public class ApiClient {
|
||||
private Map
|
||||
<String, Client> hostMap = new HashMap
|
||||
<String, Client>();
|
||||
private Map
|
||||
<String, String> defaultHeaderMap = new HashMap
|
||||
<String, String>();
|
||||
private boolean debugging = false;
|
||||
private String basePath = "{{basePath}}";
|
||||
private Map<String, Client> hostMap = new HashMap<String, Client>();
|
||||
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||
private boolean debugging = false;
|
||||
private String basePath = "{{basePath}}";
|
||||
|
||||
private Map
|
||||
<String, Authentication> authentications;
|
||||
private Map<String, Authentication> authentications;
|
||||
|
||||
private DateFormat dateFormat;
|
||||
private DateFormat dateFormat;
|
||||
|
||||
public ApiClient() {
|
||||
// Use ISO 8601 format for date and datetime.
|
||||
// See https://en.wikipedia.org/wiki/ISO_8601
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
public ApiClient() {
|
||||
// Use ISO 8601 format for date and datetime.
|
||||
// See https://en.wikipedia.org/wiki/ISO_8601
|
||||
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
|
||||
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
// Use UTC as the default time zone.
|
||||
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Java-Swagger");
|
||||
// Set default User-Agent.
|
||||
setUserAgent("Java-Swagger");
|
||||
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap
|
||||
<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||
// Setup authentications (key: authentication name, value: authentication).
|
||||
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
||||
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
// Prevent the authentications from being modified.
|
||||
authentications = Collections.unmodifiableMap(authentications);
|
||||
}
|
||||
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
public String getBasePath() {
|
||||
return basePath;
|
||||
}
|
||||
|
||||
public ApiClient setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
public ApiClient setBasePath(String basePath) {
|
||||
this.basePath = basePath;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentications (key: authentication name, value: authentication).
|
||||
*/
|
||||
public Map
|
||||
<String, Authentication> getAuthentications() {
|
||||
return authentications;
|
||||
}
|
||||
/**
|
||||
* Get authentications (key: authentication name, value: authentication).
|
||||
*/
|
||||
public Map<String, Authentication> getAuthentications() {
|
||||
return authentications;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get authentication for the given name.
|
||||
*
|
||||
* @param authName The authentication name
|
||||
* @return The authentication, null if not found
|
||||
*/
|
||||
public Authentication getAuthentication(String authName) {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
/**
|
||||
* Get authentication for the given name.
|
||||
*
|
||||
* @param authName The authentication name
|
||||
* @return The authentication, null if not found
|
||||
*/
|
||||
public Authentication getAuthentication(String authName) {
|
||||
return authentications.get(authName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set username for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setUsername(String username) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setUsername(username);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set password for the first HTTP basic authentication.
|
||||
*/
|
||||
public void setPassword(String password) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof HttpBasicAuth) {
|
||||
((HttpBasicAuth) auth).setPassword(password);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No HTTP basic authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key value for the first API key authentication.
|
||||
*/
|
||||
public void setApiKey(String apiKey) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKey(apiKey);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
/**
|
||||
* Helper method to set API key prefix for the first API key authentication.
|
||||
*/
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
for (Authentication auth : authentications.values()) {
|
||||
if (auth instanceof ApiKeyAuth) {
|
||||
((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("No API key authentication configured!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
*/
|
||||
public ApiClient setUserAgent(String userAgent) {
|
||||
addDefaultHeader("User-Agent", userAgent);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the User-Agent header's value (by adding to the default header map).
|
||||
*/
|
||||
public ApiClient setUserAgent(String userAgent) {
|
||||
addDefaultHeader("User-Agent", userAgent);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a default header.
|
||||
*
|
||||
* @param key The header's key
|
||||
* @param value The header's value
|
||||
*/
|
||||
public ApiClient addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Add a default header.
|
||||
*
|
||||
* @param key The header's key
|
||||
* @param value The header's value
|
||||
*/
|
||||
public ApiClient addDefaultHeader(String key, String value) {
|
||||
defaultHeaderMap.put(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that whether debugging is enabled for this API client.
|
||||
*/
|
||||
public boolean isDebugging() {
|
||||
return debugging;
|
||||
}
|
||||
/**
|
||||
* Check that whether debugging is enabled for this API client.
|
||||
*/
|
||||
public boolean isDebugging() {
|
||||
return debugging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/disable debugging for this API client.
|
||||
*
|
||||
* @param debugging To enable (true) or disable (false) debugging
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Enable/disable debugging for this API client.
|
||||
*
|
||||
* @param debugging To enable (true) or disable (false) debugging
|
||||
*/
|
||||
public ApiClient setDebugging(boolean debugging) {
|
||||
this.debugging = debugging;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the date format used to parse/format date parameters.
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
/**
|
||||
* Get the date format used to parse/format date parameters.
|
||||
*/
|
||||
public DateFormat getDateFormat() {
|
||||
return dateFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the date format used to parse/format date parameters.
|
||||
*/
|
||||
public ApiClient getDateFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Set the date format used to parse/format date parameters.
|
||||
*/
|
||||
public ApiClient getDateFormat(DateFormat dateFormat) {
|
||||
this.dateFormat = dateFormat;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given string into Date object.
|
||||
*/
|
||||
public Date parseDate(String str) {
|
||||
try {
|
||||
return dateFormat.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Parse the given string into Date object.
|
||||
*/
|
||||
public Date parseDate(String str) {
|
||||
try {
|
||||
return dateFormat.parse(str);
|
||||
} catch (java.text.ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given Date object into string.
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
/**
|
||||
* Format the given Date object into string.
|
||||
*/
|
||||
public String formatDate(Date date) {
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*/
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDate((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Format the given parameter object into string.
|
||||
*/
|
||||
public String parameterToString(Object param) {
|
||||
if (param == null) {
|
||||
return "";
|
||||
} else if (param instanceof Date) {
|
||||
return formatDate((Date) param);
|
||||
} else if (param instanceof Collection) {
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(Object o : (Collection)param) {
|
||||
if(b.length() > 0) {
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.valueOf(o));
|
||||
}
|
||||
return b.toString();
|
||||
} else {
|
||||
return String.valueOf(param);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use all of them (joining into a string)
|
||||
*
|
||||
* @param accepts The accepts array to select from
|
||||
* @return The Accept header to use. If the given array is empty,
|
||||
* null will be returned (not to set the Accept header explicitly).
|
||||
*/
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
if (accepts.length == 0) return null;
|
||||
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
|
||||
return StringUtil.join(accepts, ",");
|
||||
}
|
||||
/**
|
||||
* Select the Accept header's value from the given accepts array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use all of them (joining into a string)
|
||||
*
|
||||
* @param accepts The accepts array to select from
|
||||
* @return The Accept header to use. If the given array is empty,
|
||||
* null will be returned (not to set the Accept header explicitly).
|
||||
*/
|
||||
public String selectHeaderAccept(String[] accepts) {
|
||||
if (accepts.length == 0) return null;
|
||||
if (StringUtil.containsIgnoreCase(accepts, "application/json")) return "application/json";
|
||||
return StringUtil.join(accepts, ",");
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the Content-Type header's value from the given array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use the first one of the array.
|
||||
*
|
||||
* @param contentTypes The Content-Type array to select from
|
||||
* @return The Content-Type header to use. If the given array is empty,
|
||||
* JSON will be used.
|
||||
*/
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
if (contentTypes.length == 0) return "application/json";
|
||||
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json";
|
||||
return contentTypes[0];
|
||||
}
|
||||
/**
|
||||
* Select the Content-Type header's value from the given array:
|
||||
* if JSON exists in the given array, use it;
|
||||
* otherwise use the first one of the array.
|
||||
*
|
||||
* @param contentTypes The Content-Type array to select from
|
||||
* @return The Content-Type header to use. If the given array is empty,
|
||||
* JSON will be used.
|
||||
*/
|
||||
public String selectHeaderContentType(String[] contentTypes) {
|
||||
if (contentTypes.length == 0) return "application/json";
|
||||
if (StringUtil.containsIgnoreCase(contentTypes, "application/json")) return "application/json";
|
||||
return contentTypes[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape the given string to be used as URL query value.
|
||||
*/
|
||||
public String escapeString(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Escape the given string to be used as URL query value.
|
||||
*/
|
||||
public String escapeString(String str) {
|
||||
try {
|
||||
return URLEncoder.encode(str, "utf8").replaceAll("\\+", "%20");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the given JSON string to Java object.
|
||||
*
|
||||
* @param json The JSON string
|
||||
* @param containerType The container type, one of "list", "array" or ""
|
||||
* @param cls The type of the Java object
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
if(null != containerType) {
|
||||
containerType = containerType.toLowerCase();
|
||||
}
|
||||
try{
|
||||
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||
return response;
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.getJsonMapper().readValue(json, cls);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.getMessage(), null, json);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Deserialize the given JSON string to Java object.
|
||||
*
|
||||
* @param json The JSON string
|
||||
* @param containerType The container type, one of "list", "array" or ""
|
||||
* @param cls The type of the Java object
|
||||
* @return The deserialized Java object
|
||||
*/
|
||||
public Object deserialize(String json, String containerType, Class cls) throws ApiException {
|
||||
if(null != containerType) {
|
||||
containerType = containerType.toLowerCase();
|
||||
}
|
||||
try{
|
||||
if("list".equals(containerType) || "array".equals(containerType)) {
|
||||
JavaType typeInfo = JsonUtil.getJsonMapper().getTypeFactory().constructCollectionType(List.class, cls);
|
||||
List response = (List<?>) JsonUtil.getJsonMapper().readValue(json, typeInfo);
|
||||
return response;
|
||||
}
|
||||
else if(String.class.equals(cls)) {
|
||||
if(json != null && json.startsWith("\"") && json.endsWith("\"") && json.length() > 1)
|
||||
return json.substring(1, json.length() - 2);
|
||||
else
|
||||
return json;
|
||||
}
|
||||
else {
|
||||
return JsonUtil.getJsonMapper().readValue(json, cls);
|
||||
}
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new ApiException(500, e.getMessage(), null, json);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the given Java object into JSON string.
|
||||
*/
|
||||
public String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.getJsonMapper().writeValueAsString(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Serialize the given Java object into JSON string.
|
||||
*/
|
||||
public String serialize(Object obj) throws ApiException {
|
||||
try {
|
||||
if (obj != null)
|
||||
return JsonUtil.getJsonMapper().writeValueAsString(obj);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new ApiException(500, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke API by sending HTTP request with the given options.
|
||||
*
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
* @param accept The request's Accept header
|
||||
* @param contentType The request's Content-Type header
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map
|
||||
<String, String> queryParams, Object body, Map
|
||||
<String, String> headerParams, Map
|
||||
<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
/**
|
||||
* Invoke API by sending HTTP request with the given options.
|
||||
*
|
||||
* @param path The sub-path of the HTTP URL
|
||||
* @param method The request method, one of "GET", "POST", "PUT", and "DELETE"
|
||||
* @param queryParams The query parameters
|
||||
* @param body The request body object
|
||||
* @param headerParams The header parameters
|
||||
* @param formParams The form parameters
|
||||
* @param accept The request's Accept header
|
||||
* @param contentType The request's Content-Type header
|
||||
* @param authNames The authentications to apply
|
||||
* @return The response body in type of string
|
||||
*/
|
||||
public String invokeAPI(String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String accept, String contentType, String[] authNames) throws ApiException {
|
||||
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||
|
||||
Client client = getClient();
|
||||
Client client = getClient();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(String key : queryParams.keySet()) {
|
||||
String value = queryParams.get(key);
|
||||
if (value != null){
|
||||
if(b.toString().length() == 0)
|
||||
b.append("?");
|
||||
else
|
||||
b.append("&");
|
||||
b.append(escapeString(key)).append("=").append(escapeString(value));
|
||||
}
|
||||
}
|
||||
String querystring = b.toString();
|
||||
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
builder = client.resource(basePath + path + querystring).getRequestBuilder();
|
||||
else
|
||||
builder = client.resource(basePath + path + querystring).accept(accept);
|
||||
Builder builder;
|
||||
if (accept == null)
|
||||
builder = client.resource(basePath + path + querystring).getRequestBuilder();
|
||||
else
|
||||
builder = client.resource(basePath + path + querystring).accept(accept);
|
||||
|
||||
for(String key : headerParams.keySet()) {
|
||||
builder = builder.header(key, headerParams.get(key));
|
||||
}
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
builder = builder.header(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
for(String key : headerParams.keySet()) {
|
||||
builder = builder.header(key, headerParams.get(key));
|
||||
}
|
||||
for(String key : defaultHeaderMap.keySet()) {
|
||||
if(!headerParams.containsKey(key)) {
|
||||
builder = builder.header(key, defaultHeaderMap.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
ClientResponse response = null;
|
||||
ClientResponse response = null;
|
||||
|
||||
if("GET".equals(method)) {
|
||||
response = (ClientResponse) builder.get(ClientResponse.class);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).post(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if (body == null) {
|
||||
response = builder.post(ClientResponse.class, null);
|
||||
} else if(body instanceof FormDataMultiPart) {
|
||||
response = builder.type(contentType).post(ClientResponse.class, body);
|
||||
}
|
||||
else
|
||||
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).put(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.put(ClientResponse.class, serialize(body));
|
||||
} else {
|
||||
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).delete(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.delete(ClientResponse.class);
|
||||
} else {
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ApiException(500, "unknown method type " + method);
|
||||
}
|
||||
if("GET".equals(method)) {
|
||||
response = (ClientResponse) builder.get(ClientResponse.class);
|
||||
}
|
||||
else if ("POST".equals(method)) {
|
||||
if (contentType.startsWith("application/x-www-form-urlencoded")) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).post(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if (body == null) {
|
||||
response = builder.post(ClientResponse.class, null);
|
||||
} else if(body instanceof FormDataMultiPart) {
|
||||
response = builder.type(contentType).post(ClientResponse.class, body);
|
||||
}
|
||||
else
|
||||
response = builder.type(contentType).post(ClientResponse.class, serialize(body));
|
||||
}
|
||||
else if ("PUT".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).put(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.put(ClientResponse.class, serialize(body));
|
||||
} else {
|
||||
response = builder.type(contentType).put(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else if ("DELETE".equals(method)) {
|
||||
if ("application/x-www-form-urlencoded".equals(contentType)) {
|
||||
String encodedFormParams = this
|
||||
.getXWWWFormUrlencodedParams(formParams);
|
||||
response = builder.type(contentType).delete(ClientResponse.class,
|
||||
encodedFormParams);
|
||||
} else if(body == null) {
|
||||
response = builder.delete(ClientResponse.class);
|
||||
} else {
|
||||
response = builder.type(contentType).delete(ClientResponse.class, serialize(body));
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new ApiException(500, "unknown method type " + method);
|
||||
}
|
||||
|
||||
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
String respBody = null;
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
respBody = String.valueOf(response.getEntity(String.class));
|
||||
message = respBody;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
message,
|
||||
response.getHeaders(),
|
||||
respBody);
|
||||
}
|
||||
}
|
||||
if(response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
|
||||
return null;
|
||||
}
|
||||
else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
|
||||
if(response.hasEntity()) {
|
||||
return (String) response.getEntity(String.class);
|
||||
}
|
||||
else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
else {
|
||||
String message = "error";
|
||||
String respBody = null;
|
||||
if(response.hasEntity()) {
|
||||
try{
|
||||
respBody = String.valueOf(response.getEntity(String.class));
|
||||
message = respBody;
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
throw new ApiException(
|
||||
response.getClientResponseStatus().getStatusCode(),
|
||||
message,
|
||||
response.getHeaders(),
|
||||
respBody);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update query and header parameters based on authentication settings.
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Update query and header parameters based on authentication settings.
|
||||
*
|
||||
* @param authNames The authentications to apply
|
||||
*/
|
||||
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
for (String authName : authNames) {
|
||||
Authentication auth = authentications.get(authName);
|
||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);
|
||||
auth.applyToParams(queryParams, headerParams);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode the given form parameters as request body.
|
||||
*/
|
||||
private String getXWWWFormUrlencodedParams(Map
|
||||
<String, String> formParams) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
/**
|
||||
* Encode the given form parameters as request body.
|
||||
*/
|
||||
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
|
||||
StringBuilder formParamBuilder = new StringBuilder();
|
||||
|
||||
for (Entry
|
||||
<String, String> param : formParams.entrySet()) {
|
||||
String keyStr = parameterToString(param.getKey());
|
||||
String valueStr = parameterToString(param.getValue());
|
||||
for (Entry<String, String> param : formParams.entrySet()) {
|
||||
String keyStr = parameterToString(param.getKey());
|
||||
String valueStr = parameterToString(param.getValue());
|
||||
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(valueStr, "utf8"));
|
||||
formParamBuilder.append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
String encodedFormParams = formParamBuilder.toString();
|
||||
if (encodedFormParams.endsWith("&")) {
|
||||
encodedFormParams = encodedFormParams.substring(0,
|
||||
encodedFormParams.length() - 1);
|
||||
}
|
||||
return encodedFormParams;
|
||||
}
|
||||
try {
|
||||
formParamBuilder.append(URLEncoder.encode(keyStr, "utf8"))
|
||||
.append("=")
|
||||
.append(URLEncoder.encode(valueStr, "utf8"));
|
||||
formParamBuilder.append("&");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
// move on to next
|
||||
}
|
||||
}
|
||||
String encodedFormParams = formParamBuilder.toString();
|
||||
if (encodedFormParams.endsWith("&")) {
|
||||
encodedFormParams = encodedFormParams.substring(0,
|
||||
encodedFormParams.length() - 1);
|
||||
}
|
||||
return encodedFormParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing client or create a new client to handle HTTP request.
|
||||
*/
|
||||
private Client getClient() {
|
||||
if(!hostMap.containsKey(basePath)) {
|
||||
Client client = Client.create();
|
||||
if (debugging)
|
||||
client.addFilter(new LoggingFilter());
|
||||
hostMap.put(basePath, client);
|
||||
}
|
||||
return hostMap.get(basePath);
|
||||
}
|
||||
/**
|
||||
* Get an existing client or create a new client to handle HTTP request.
|
||||
*/
|
||||
private Client getClient() {
|
||||
if(!hostMap.containsKey(basePath)) {
|
||||
Client client = Client.create();
|
||||
if (debugging)
|
||||
client.addFilter(new LoggingFilter());
|
||||
hostMap.put(basePath, client);
|
||||
}
|
||||
return hostMap.get(basePath);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class Configuration {
|
||||
private static ApiClient defaultApiClient = new ApiClient();
|
||||
private static ApiClient defaultApiClient = new ApiClient();
|
||||
|
||||
/**
|
||||
* Get the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static ApiClient getDefaultApiClient() {
|
||||
return defaultApiClient;
|
||||
}
|
||||
/**
|
||||
* Get the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static ApiClient getDefaultApiClient() {
|
||||
return defaultApiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static void setDefaultApiClient(ApiClient apiClient) {
|
||||
defaultApiClient = apiClient;
|
||||
}
|
||||
/**
|
||||
* Set the default API client, which would be used when creating API
|
||||
* instances without providing an API client.
|
||||
*/
|
||||
public static void setDefaultApiClient(ApiClient apiClient) {
|
||||
defaultApiClient = apiClient;
|
||||
}
|
||||
}
|
||||
|
@ -8,16 +8,16 @@ import com.fasterxml.jackson.core.JsonGenerator.Feature;
|
||||
import com.fasterxml.jackson.datatype.joda.*;
|
||||
|
||||
public class JsonUtil {
|
||||
public static ObjectMapper mapper;
|
||||
public static ObjectMapper mapper;
|
||||
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
static {
|
||||
mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
mapper.registerModule(new JodaModule());
|
||||
}
|
||||
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
public static ObjectMapper getJsonMapper() {
|
||||
return mapper;
|
||||
}
|
||||
}
|
||||
|
@ -1,41 +1,41 @@
|
||||
package {{invokerPackage}};
|
||||
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) return true;
|
||||
if (value != null && value.equalsIgnoreCase(str)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
*
|
||||
* @param array The array
|
||||
* @param value The value to search
|
||||
* @return true if the array contains the value
|
||||
*/
|
||||
public static boolean containsIgnoreCase(String[] array, String value) {
|
||||
for (String str : array) {
|
||||
if (value == null && str == null) return true;
|
||||
if (value != null && value.equalsIgnoreCase(str)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
/**
|
||||
* Join an array of strings with the given separator.
|
||||
* <p>
|
||||
* Note: This might be replaced by utility method from commons-lang or guava someday
|
||||
* if one of those libraries is added as dependency.
|
||||
* </p>
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) return "";
|
||||
*
|
||||
* @param array The array of strings
|
||||
* @param separator The separator
|
||||
* @return the resulting string
|
||||
*/
|
||||
public static String join(String[] array, String separator) {
|
||||
int len = array.length;
|
||||
if (len == 0) return "";
|
||||
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append(array[0]);
|
||||
for (int i = 1; i < len; i++) {
|
||||
out.append(separator).append(array[i]);
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
{{#operations}}
|
||||
public class {{classname}} {
|
||||
public class {{classname}} {
|
||||
private ApiClient apiClient;
|
||||
|
||||
public {{classname}}() {
|
||||
@ -44,8 +44,8 @@ import java.util.HashMap;
|
||||
/**
|
||||
* {{summary}}
|
||||
* {{notes}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
{{#allParams}} * @param {{paramName}} {{description}}
|
||||
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
|
||||
*/
|
||||
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
|
||||
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
|
||||
@ -61,15 +61,9 @@ import java.util.HashMap;
|
||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||
|
||||
// query params
|
||||
Map
|
||||
<String, String> queryParams = new HashMap
|
||||
<String, String>();
|
||||
Map
|
||||
<String, String> headerParams = new HashMap
|
||||
<String, String>();
|
||||
Map
|
||||
<String, String> formParams = new HashMap
|
||||
<String, String>();
|
||||
Map<String, String> queryParams = new HashMap<String, String>();
|
||||
Map<String, String> headerParams = new HashMap<String, String>();
|
||||
Map<String, String> formParams = new HashMap<String, String>();
|
||||
|
||||
{{#queryParams}}if ({{paramName}} != null)
|
||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||
@ -127,5 +121,5 @@ import java.util.HashMap;
|
||||
}
|
||||
}
|
||||
{{/operation}}
|
||||
}
|
||||
}
|
||||
{{/operations}}
|
||||
|
@ -4,11 +4,9 @@ import java.util.Map;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiException extends Exception {
|
||||
private int code = 0;
|
||||
private String message = null;
|
||||
private Map
|
||||
<String, List
|
||||
<String>> responseHeaders = null;
|
||||
private int code = 0;
|
||||
private String message = null;
|
||||
private Map<String, List<String>> responseHeaders = null;
|
||||
private String responseBody = null;
|
||||
|
||||
public ApiException() {}
|
||||
@ -18,10 +16,7 @@ private Map
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public ApiException(int code, String message, Map
|
||||
<String
|
||||
, List
|
||||
<String>> responseHeaders, String responseBody) {
|
||||
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
this.responseHeaders = responseHeaders;
|
||||
@ -39,10 +34,7 @@ private Map
|
||||
/**
|
||||
* Get the HTTP response headers.
|
||||
*/
|
||||
public Map
|
||||
<String
|
||||
, List
|
||||
<String>> getResponseHeaders() {
|
||||
public Map<String, List<String>> getResponseHeaders() {
|
||||
return responseHeaders;
|
||||
}
|
||||
|
||||
@ -52,4 +44,4 @@ private Map
|
||||
public String getResponseBody() {
|
||||
return responseBody;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,55 +3,53 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public class ApiKeyAuth implements Authentication {
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
private final String location;
|
||||
private final String paramName;
|
||||
|
||||
private String apiKey;
|
||||
private String apiKeyPrefix;
|
||||
private String apiKey;
|
||||
private String apiKeyPrefix;
|
||||
|
||||
public ApiKeyAuth(String location, String paramName) {
|
||||
this.location = location;
|
||||
this.paramName = paramName;
|
||||
}
|
||||
public ApiKeyAuth(String location, String paramName) {
|
||||
this.location = location;
|
||||
this.paramName = paramName;
|
||||
}
|
||||
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
public String getParamName() {
|
||||
return paramName;
|
||||
}
|
||||
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
public String getApiKey() {
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
public void setApiKey(String apiKey) {
|
||||
this.apiKey = apiKey;
|
||||
}
|
||||
|
||||
public String getApiKeyPrefix() {
|
||||
return apiKeyPrefix;
|
||||
}
|
||||
public String getApiKeyPrefix() {
|
||||
return apiKeyPrefix;
|
||||
}
|
||||
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
this.apiKeyPrefix = apiKeyPrefix;
|
||||
}
|
||||
public void setApiKeyPrefix(String apiKeyPrefix) {
|
||||
this.apiKeyPrefix = apiKeyPrefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String value;
|
||||
if (apiKeyPrefix != null) {
|
||||
value = apiKeyPrefix + " " + apiKey;
|
||||
} else {
|
||||
value = apiKey;
|
||||
}
|
||||
if (location == "query") {
|
||||
queryParams.put(paramName, value);
|
||||
} else if (location == "header") {
|
||||
headerParams.put(paramName, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public interface Authentication {
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams);
|
||||
/** Apply authentication settings to header and query params. */
|
||||
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||
}
|
||||
|
@ -6,34 +6,32 @@ import java.io.UnsupportedEncodingException;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
|
||||
public class HttpBasicAuth implements Authentication {
|
||||
private String username;
|
||||
private String password;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||
try {
|
||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,8 @@ package {{invokerPackage}}.auth;
|
||||
import java.util.Map;
|
||||
|
||||
public class OAuth implements Authentication {
|
||||
@Override
|
||||
public void applyToParams(Map
|
||||
<String, String> queryParams, Map
|
||||
<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
@Override
|
||||
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||
// TODO: support oauth
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ import io.swagger.annotations.*;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{#models}}
|
||||
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
{{#model}}{{#description}}
|
||||
/**
|
||||
* {{description}}
|
||||
**/{{/description}}
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
@ApiModel(description = "{{{description}}}")
|
||||
public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {
|
||||
{{#vars}}{{#isEnum}}
|
||||
public enum {{datatypeWithEnum}} {
|
||||
{{#allowableValues}}{{#values}} {{.}}, {{/values}}{{/allowableValues}}
|
||||
@ -46,6 +46,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
{{/vars}}sb.append("}\n");
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
{{/model}}
|
||||
}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
@ -77,8 +77,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/main/java</source>
|
||||
<source>src/main/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
@ -90,8 +89,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>
|
||||
src/test/java</source>
|
||||
<source>src/test/java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
@ -102,8 +100,7 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.6</source>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
Loading…
x
Reference in New Issue
Block a user