rollback java template

This commit is contained in:
wing328 2015-06-09 13:08:32 +08:00
parent 900f39686d
commit 180d48e89d
12 changed files with 857 additions and 896 deletions

View File

@ -40,17 +40,12 @@ 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 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;
@ -66,8 +61,7 @@ this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
setUserAgent("Java-Swagger");
// Setup authentications (key: authentication name, value: authentication).
authentications = new HashMap
<String, Authentication>();{{#authMethods}}{{#isBasic}}
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}}
@ -87,8 +81,7 @@ return this;
/**
* Get authentications (key: authentication name, value: authentication).
*/
public Map
<String, Authentication> getAuthentications() {
public Map<String, Authentication> getAuthentications() {
return authentications;
}
@ -348,10 +341,7 @@ throw new ApiException(500, e.getMessage());
* @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 {
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();
@ -467,9 +457,7 @@ respBody);
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Map
<String, String> queryParams, Map
<String, String> headerParams) {
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);
@ -480,12 +468,10 @@ auth.applyToParams(queryParams, headerParams);
/**
* Encode the given form parameters as request body.
*/
private String getXWWWFormUrlencodedParams(Map
<String, String> formParams) {
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
StringBuilder formParamBuilder = new StringBuilder();
for (Entry
<String, String> param : formParams.entrySet()) {
for (Entry<String, String> param : formParams.entrySet()) {
String keyStr = parameterToString(param.getKey());
String valueStr = parameterToString(param.getValue());

View File

@ -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}}));

View File

@ -6,9 +6,7 @@ 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 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;
}

View File

@ -39,9 +39,7 @@ this.apiKeyPrefix = apiKeyPrefix;
}
@Override
public void applyToParams(Map
<String, String> queryParams, Map
<String, String> headerParams) {
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@ -4,7 +4,5 @@ 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);
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
}

View File

@ -26,9 +26,7 @@ this.password = password;
}
@Override
public void applyToParams(Map
<String, String> queryParams, Map
<String, String> headerParams) {
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")));

View File

@ -4,9 +4,7 @@ import java.util.Map;
public class OAuth implements Authentication {
@Override
public void applyToParams(Map
<String, String> queryParams, Map
<String, String> headerParams) {
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
}

View File

@ -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>