Refactored Pairs to use List instead of Set.

This commit is contained in:
Raghav Sidhanti
2015-06-22 17:14:18 -07:00
parent 32b50e7c8e
commit 6958db3d3d
22 changed files with 83 additions and 87 deletions

View File

@@ -22,8 +22,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.TimeZone;
@@ -243,8 +242,8 @@ public class ApiClient {
/*
Format to {@code Pair} objects.
*/
public Set<Pair> parameterToPairs(String collectionFormat, String name, Object value){
Set<Pair> params = new HashSet<Pair>();
public List<Pair> parameterToPairs(String collectionFormat, String name, Object value){
List<Pair> params = new ArrayList<Pair>();
// preconditions
if (name == null || name.isEmpty()) return params;
@@ -404,7 +403,7 @@ public class ApiClient {
* @param authNames The authentications to apply
* @return The response body in type of string
*/
public String invokeAPI(String path, String method, Set<Pair> 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, List<Pair> 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();
@@ -522,7 +521,7 @@ public class ApiClient {
*
* @param authNames The authentications to apply
*/
private void updateParamsForAuth(String[] authNames, Set<Pair> queryParams, Map<String, String> headerParams) {
private void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<String, String> headerParams) {
for (String authName : authNames) {
Authentication auth = authentications.get(authName);
if (auth == null) throw new RuntimeException("Authentication undefined: " + authName);

View File

@@ -62,7 +62,7 @@ public class {{classname}} {
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
// query params
Set<Pair> queryParams = new HashSet<Pair>();
List<Pair> queryParams = new ArrayList<Pair>();
Map<String, String> headerParams = new HashMap<String, String>();
Map<String, String> formParams = new HashMap<String, String>();

View File

@@ -3,7 +3,7 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
import java.util.List;
public class ApiKeyAuth implements Authentication {
private final String location;
@@ -42,7 +42,7 @@ public class ApiKeyAuth implements Authentication {
}
@Override
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
String value;
if (apiKeyPrefix != null) {
value = apiKeyPrefix + " " + apiKey;

View File

@@ -3,9 +3,9 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
import java.util.List;
public interface Authentication {
/** Apply authentication settings to header and query params. */
void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams);
void applyToParams(List<Pair> queryParams, Map<String, String> headerParams);
}

View File

@@ -3,7 +3,7 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.io.UnsupportedEncodingException;
import javax.xml.bind.DatatypeConverter;
@@ -29,7 +29,7 @@ public class HttpBasicAuth implements Authentication {
}
@Override
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
public void applyToParams(List<Pair> 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

@@ -3,11 +3,11 @@ package {{invokerPackage}}.auth;
import {{invokerPackage}}.Pair;
import java.util.Map;
import java.util.Set;
import java.util.List;
public class OAuth implements Authentication {
@Override
public void applyToParams(Set<Pair> queryParams, Map<String, String> headerParams) {
public void applyToParams(List<Pair> queryParams, Map<String, String> headerParams) {
// TODO: support oauth
}
}