Skip to content

Commit e10e1f5

Browse files
committed
Refactor auth method naming, add comments
1 parent 6eb1a89 commit e10e1f5

File tree

12 files changed

+24
-20
lines changed

12 files changed

+24
-20
lines changed

modules/swagger-codegen/src/main/resources/Java/apiInvoker.mustache

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public class ApiInvoker {
166166
}
167167

168168
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames) throws ApiException {
169-
processAuthParams(authNames, queryParams, headerParams);
169+
updateParamsForAuth(authNames, queryParams, headerParams);
170170
171171
Client client = getClient(host);
172172
@@ -266,11 +266,12 @@ public class ApiInvoker {
266266
}
267267
}
268268

269-
private void processAuthParams(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
269+
/* Update hearder and query params based on authentication settings. */
270+
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
270271
for (String authName : authNames) {
271272
Authentication auth = Configuration.getAuthentication(authName);
272273
if (auth == null) throw new RuntimeException("Authentication has not been setup for " + authName);
273-
auth.processParams(queryParams, headerParams);
274+
auth.applyToParams(queryParams, headerParams);
274275
}
275276
}
276277

modules/swagger-codegen/src/main/resources/Java/auth/ApiKeyAuth.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ApiKeyAuth implements Authentication {
3939
}
4040

4141
@Override
42-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
42+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
4343
String value;
4444
if (apiKeyPrefix != null) {
4545
value = apiKeyPrefix + " " + apiKey;

modules/swagger-codegen/src/main/resources/Java/auth/Authentication.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ package {{invokerPackage}}.auth;
33
import java.util.Map;
44

55
public interface Authentication {
6-
void processParams(Map<String, String> queryParams, Map<String, String> headerParams);
6+
/** Apply authentication settings to header and query params. */
7+
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
78
}

modules/swagger-codegen/src/main/resources/Java/auth/HttpBasicAuth.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class HttpBasicAuth implements Authentication {
2626
}
2727

2828
@Override
29-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
29+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
3030
try {
3131
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("UTF-8")));
3232
} catch (UnsupportedEncodingException e) {

modules/swagger-codegen/src/main/resources/Java/auth/OAuth.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import java.util.Map;
44

55
public class OAuth implements Authentication {
66
@Override
7-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
7+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
88
// TODO: support oauth
99
}
1010
}

samples/client/petstore/java/src/main/java/io/swagger/client/ApiInvoker.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static String serialize(Object obj) throws ApiException {
166166
}
167167

168168
public String invokeAPI(String host, String path, String method, Map<String, String> queryParams, Object body, Map<String, String> headerParams, Map<String, String> formParams, String contentType, String[] authNames) throws ApiException {
169-
processAuthParams(authNames, queryParams, headerParams);
169+
updateParamsForAuth(authNames, queryParams, headerParams);
170170

171171
Client client = getClient(host);
172172

@@ -266,11 +266,12 @@ else if(response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) {
266266
}
267267
}
268268

269-
private void processAuthParams(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
269+
/* Update hearder and query params based on authentication settings. */
270+
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
270271
for (String authName : authNames) {
271272
Authentication auth = Configuration.getAuthentication(authName);
272273
if (auth == null) throw new RuntimeException("Authentication has not been setup for " + authName);
273-
auth.processParams(queryParams, headerParams);
274+
auth.applyToParams(queryParams, headerParams);
274275
}
275276
}
276277

samples/client/petstore/java/src/main/java/io/swagger/client/auth/ApiKeyAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void setApiKeyPrefix(String apiKeyPrefix) {
3939
}
4040

4141
@Override
42-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
42+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
4343
String value;
4444
if (apiKeyPrefix != null) {
4545
value = apiKeyPrefix + " " + apiKey;

samples/client/petstore/java/src/main/java/io/swagger/client/auth/Authentication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
import java.util.Map;
44

55
public interface Authentication {
6-
void processParams(Map<String, String> queryParams, Map<String, String> headerParams);
6+
/** Apply authentication settings to header and query params. */
7+
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
78
}

samples/client/petstore/java/src/main/java/io/swagger/client/auth/HttpBasicAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void setPassword(String password) {
2626
}
2727

2828
@Override
29-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
29+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
3030
try {
3131
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary((username + ":" + password).getBytes("UTF-8")));
3232
} catch (UnsupportedEncodingException e) {

samples/client/petstore/java/src/main/java/io/swagger/client/auth/OAuth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public class OAuth implements Authentication {
66
@Override
7-
public void processParams(Map<String, String> queryParams, Map<String, String> headerParams) {
7+
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
88
// TODO: support oauth
99
}
1010
}

0 commit comments

Comments
 (0)