forked from loafle/openapi-generator-original
rollback java template
This commit is contained in:
parent
900f39686d
commit
180d48e89d
@ -40,17 +40,12 @@ import {{invokerPackage}}.auth.ApiKeyAuth;
|
|||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
|
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
private Map
|
private Map<String, Client> hostMap = new HashMap<String, Client>();
|
||||||
<String, Client> hostMap = new HashMap
|
private Map<String, String> defaultHeaderMap = new HashMap<String, String>();
|
||||||
<String, Client>();
|
|
||||||
private Map
|
|
||||||
<String, String> defaultHeaderMap = new HashMap
|
|
||||||
<String, String>();
|
|
||||||
private boolean debugging = false;
|
private boolean debugging = false;
|
||||||
private String basePath = "{{basePath}}";
|
private String basePath = "{{basePath}}";
|
||||||
|
|
||||||
private Map
|
private Map<String, Authentication> authentications;
|
||||||
<String, Authentication> authentications;
|
|
||||||
|
|
||||||
private DateFormat dateFormat;
|
private DateFormat dateFormat;
|
||||||
|
|
||||||
@ -66,8 +61,7 @@ this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
|
|||||||
setUserAgent("Java-Swagger");
|
setUserAgent("Java-Swagger");
|
||||||
|
|
||||||
// Setup authentications (key: authentication name, value: authentication).
|
// Setup authentications (key: authentication name, value: authentication).
|
||||||
authentications = new HashMap
|
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
||||||
<String, Authentication>();{{#authMethods}}{{#isBasic}}
|
|
||||||
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
|
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 ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
|
||||||
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
|
||||||
@ -87,8 +81,7 @@ return this;
|
|||||||
/**
|
/**
|
||||||
* Get authentications (key: authentication name, value: authentication).
|
* Get authentications (key: authentication name, value: authentication).
|
||||||
*/
|
*/
|
||||||
public Map
|
public Map<String, Authentication> getAuthentications() {
|
||||||
<String, Authentication> getAuthentications() {
|
|
||||||
return authentications;
|
return authentications;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,10 +341,7 @@ throw new ApiException(500, e.getMessage());
|
|||||||
* @param authNames The authentications to apply
|
* @param authNames The authentications to apply
|
||||||
* @return The response body in type of string
|
* @return The response body in type of string
|
||||||
*/
|
*/
|
||||||
public String invokeAPI(String path, String method, Map
|
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 {
|
||||||
<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);
|
updateParamsForAuth(authNames, queryParams, headerParams);
|
||||||
|
|
||||||
Client client = getClient();
|
Client client = getClient();
|
||||||
@ -467,9 +457,7 @@ respBody);
|
|||||||
*
|
*
|
||||||
* @param authNames The authentications to apply
|
* @param authNames The authentications to apply
|
||||||
*/
|
*/
|
||||||
private void updateParamsForAuth(String[] authNames, Map
|
private void updateParamsForAuth(String[] authNames, Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||||
<String, String> queryParams, Map
|
|
||||||
<String, String> headerParams) {
|
|
||||||
for (String authName : authNames) {
|
for (String authName : authNames) {
|
||||||
Authentication auth = authentications.get(authName);
|
Authentication auth = authentications.get(authName);
|
||||||
if (auth == null) throw new RuntimeException("Authentication undefined: " + 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.
|
* Encode the given form parameters as request body.
|
||||||
*/
|
*/
|
||||||
private String getXWWWFormUrlencodedParams(Map
|
private String getXWWWFormUrlencodedParams(Map<String, String> formParams) {
|
||||||
<String, String> formParams) {
|
|
||||||
StringBuilder formParamBuilder = new StringBuilder();
|
StringBuilder formParamBuilder = new StringBuilder();
|
||||||
|
|
||||||
for (Entry
|
for (Entry<String, String> param : formParams.entrySet()) {
|
||||||
<String, String> param : formParams.entrySet()) {
|
|
||||||
String keyStr = parameterToString(param.getKey());
|
String keyStr = parameterToString(param.getKey());
|
||||||
String valueStr = parameterToString(param.getValue());
|
String valueStr = parameterToString(param.getValue());
|
||||||
|
|
||||||
|
@ -61,15 +61,9 @@ import java.util.HashMap;
|
|||||||
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
|
||||||
|
|
||||||
// query params
|
// query params
|
||||||
Map
|
Map<String, String> queryParams = new HashMap<String, String>();
|
||||||
<String, String> queryParams = new HashMap
|
Map<String, String> headerParams = new HashMap<String, String>();
|
||||||
<String, String>();
|
Map<String, String> formParams = 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}}if ({{paramName}} != null)
|
||||||
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
|
||||||
|
@ -6,9 +6,7 @@ import java.util.List;
|
|||||||
public class ApiException extends Exception {
|
public class ApiException extends Exception {
|
||||||
private int code = 0;
|
private int code = 0;
|
||||||
private String message = null;
|
private String message = null;
|
||||||
private Map
|
private Map<String, List<String>> responseHeaders = null;
|
||||||
<String, List
|
|
||||||
<String>> responseHeaders = null;
|
|
||||||
private String responseBody = null;
|
private String responseBody = null;
|
||||||
|
|
||||||
public ApiException() {}
|
public ApiException() {}
|
||||||
@ -18,10 +16,7 @@ private Map
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ApiException(int code, String message, Map
|
public ApiException(int code, String message, Map<String, List<String>> responseHeaders, String responseBody) {
|
||||||
<String
|
|
||||||
, List
|
|
||||||
<String>> responseHeaders, String responseBody) {
|
|
||||||
this.code = code;
|
this.code = code;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.responseHeaders = responseHeaders;
|
this.responseHeaders = responseHeaders;
|
||||||
@ -39,10 +34,7 @@ private Map
|
|||||||
/**
|
/**
|
||||||
* Get the HTTP response headers.
|
* Get the HTTP response headers.
|
||||||
*/
|
*/
|
||||||
public Map
|
public Map<String, List<String>> getResponseHeaders() {
|
||||||
<String
|
|
||||||
, List
|
|
||||||
<String>> getResponseHeaders() {
|
|
||||||
return responseHeaders;
|
return responseHeaders;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,9 +39,7 @@ this.apiKeyPrefix = apiKeyPrefix;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyToParams(Map
|
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||||
<String, String> queryParams, Map
|
|
||||||
<String, String> headerParams) {
|
|
||||||
String value;
|
String value;
|
||||||
if (apiKeyPrefix != null) {
|
if (apiKeyPrefix != null) {
|
||||||
value = apiKeyPrefix + " " + apiKey;
|
value = apiKeyPrefix + " " + apiKey;
|
||||||
|
@ -4,7 +4,5 @@ import java.util.Map;
|
|||||||
|
|
||||||
public interface Authentication {
|
public interface Authentication {
|
||||||
/** Apply authentication settings to header and query params. */
|
/** Apply authentication settings to header and query params. */
|
||||||
void applyToParams(Map
|
void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams);
|
||||||
<String, String> queryParams, Map
|
|
||||||
<String, String> headerParams);
|
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,7 @@ this.password = password;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyToParams(Map
|
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||||
<String, String> queryParams, Map
|
|
||||||
<String, String> headerParams) {
|
|
||||||
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
String str = (username == null ? "" : username) + ":" + (password == null ? "" : password);
|
||||||
try {
|
try {
|
||||||
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
headerParams.put("Authorization", "Basic " + DatatypeConverter.printBase64Binary(str.getBytes("UTF-8")));
|
||||||
|
@ -4,9 +4,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class OAuth implements Authentication {
|
public class OAuth implements Authentication {
|
||||||
@Override
|
@Override
|
||||||
public void applyToParams(Map
|
public void applyToParams(Map<String, String> queryParams, Map<String, String> headerParams) {
|
||||||
<String, String> queryParams, Map
|
|
||||||
<String, String> headerParams) {
|
|
||||||
// TODO: support oauth
|
// TODO: support oauth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,8 +77,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/main/java</source>
|
||||||
src/main/java</source>
|
|
||||||
</sources>
|
</sources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -90,8 +89,7 @@
|
|||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<sources>
|
<sources>
|
||||||
<source>
|
<source>src/test/java</source>
|
||||||
src/test/java</source>
|
|
||||||
</sources>
|
</sources>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
@ -102,8 +100,7 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>
|
<source>1.6</source>
|
||||||
1.6</source>
|
|
||||||
<target>1.6</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user