Skip to content

Commit 180d48e

Browse files
committed
rollback java template
1 parent 900f396 commit 180d48e

File tree

12 files changed

+917
-956
lines changed

12 files changed

+917
-956
lines changed

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

Lines changed: 458 additions & 472 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
package {{invokerPackage}};
22

33
public class Configuration {
4-
private static ApiClient defaultApiClient = new ApiClient();
4+
private static ApiClient defaultApiClient = new ApiClient();
55
6-
/**
7-
* Get the default API client, which would be used when creating API
8-
* instances without providing an API client.
9-
*/
10-
public static ApiClient getDefaultApiClient() {
11-
return defaultApiClient;
12-
}
6+
/**
7+
* Get the default API client, which would be used when creating API
8+
* instances without providing an API client.
9+
*/
10+
public static ApiClient getDefaultApiClient() {
11+
return defaultApiClient;
12+
}
1313

14-
/**
15-
* Set the default API client, which would be used when creating API
16-
* instances without providing an API client.
17-
*/
18-
public static void setDefaultApiClient(ApiClient apiClient) {
19-
defaultApiClient = apiClient;
20-
}
14+
/**
15+
* Set the default API client, which would be used when creating API
16+
* instances without providing an API client.
17+
*/
18+
public static void setDefaultApiClient(ApiClient apiClient) {
19+
defaultApiClient = apiClient;
20+
}
2121
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import com.fasterxml.jackson.core.JsonGenerator.Feature;
88
import com.fasterxml.jackson.datatype.joda.*;
99

1010
public class JsonUtil {
11-
public static ObjectMapper mapper;
11+
public static ObjectMapper mapper;
1212
13-
static {
14-
mapper = new ObjectMapper();
15-
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
16-
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
17-
mapper.registerModule(new JodaModule());
18-
}
13+
static {
14+
mapper = new ObjectMapper();
15+
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
16+
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
17+
mapper.registerModule(new JodaModule());
18+
}
1919

20-
public static ObjectMapper getJsonMapper() {
21-
return mapper;
22-
}
20+
public static ObjectMapper getJsonMapper() {
21+
return mapper;
22+
}
2323
}
Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
package {{invokerPackage}};
22

33
public class StringUtil {
4-
/**
5-
* Check if the given array contains the given value (with case-insensitive comparison).
6-
*
7-
* @param array The array
8-
* @param value The value to search
9-
* @return true if the array contains the value
10-
*/
11-
public static boolean containsIgnoreCase(String[] array, String value) {
12-
for (String str : array) {
13-
if (value == null && str == null) return true;
14-
if (value != null && value.equalsIgnoreCase(str)) return true;
15-
}
16-
return false;
17-
}
4+
/**
5+
* Check if the given array contains the given value (with case-insensitive comparison).
6+
*
7+
* @param array The array
8+
* @param value The value to search
9+
* @return true if the array contains the value
10+
*/
11+
public static boolean containsIgnoreCase(String[] array, String value) {
12+
for (String str : array) {
13+
if (value == null && str == null) return true;
14+
if (value != null && value.equalsIgnoreCase(str)) return true;
15+
}
16+
return false;
17+
}
1818

19-
/**
20-
* Join an array of strings with the given separator.
21-
* <p>
22-
* Note: This might be replaced by utility method from commons-lang or guava someday
23-
* if one of those libraries is added as dependency.
24-
* </p>
25-
*
26-
* @param array The array of strings
27-
* @param separator The separator
28-
* @return the resulting string
29-
*/
30-
public static String join(String[] array, String separator) {
31-
int len = array.length;
32-
if (len == 0) return "";
19+
/**
20+
* Join an array of strings with the given separator.
21+
* <p>
22+
* Note: This might be replaced by utility method from commons-lang or guava someday
23+
* if one of those libraries is added as dependency.
24+
* </p>
25+
*
26+
* @param array The array of strings
27+
* @param separator The separator
28+
* @return the resulting string
29+
*/
30+
public static String join(String[] array, String separator) {
31+
int len = array.length;
32+
if (len == 0) return "";
3333
34-
StringBuilder out = new StringBuilder();
35-
out.append(array[0]);
36-
for (int i = 1; i < len; i++) {
37-
out.append(separator).append(array[i]);
38-
}
39-
return out.toString();
40-
}
34+
StringBuilder out = new StringBuilder();
35+
out.append(array[0]);
36+
for (int i = 1; i < len; i++) {
37+
out.append(separator).append(array[i]);
38+
}
39+
return out.toString();
40+
}
4141
}

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

Lines changed: 86 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -21,111 +21,105 @@ import java.util.Map;
2121
import java.util.HashMap;
2222

2323
{{#operations}}
24-
public class {{classname}} {
25-
private ApiClient apiClient;
24+
public class {{classname}} {
25+
private ApiClient apiClient;
2626
27-
public {{classname}}() {
27+
public {{classname}}() {
2828
this(Configuration.getDefaultApiClient());
29-
}
29+
}
3030

31-
public {{classname}}(ApiClient apiClient) {
31+
public {{classname}}(ApiClient apiClient) {
3232
this.apiClient = apiClient;
33-
}
33+
}
3434

35-
public ApiClient getApiClient() {
35+
public ApiClient getApiClient() {
3636
return apiClient;
37-
}
37+
}
3838

39-
public void setApiClient(ApiClient apiClient) {
39+
public void setApiClient(ApiClient apiClient) {
4040
this.apiClient = apiClient;
41+
}
42+
43+
{{#operation}}
44+
/**
45+
* {{summary}}
46+
* {{notes}}
47+
{{#allParams}} * @param {{paramName}} {{description}}
48+
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
49+
*/
50+
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
51+
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
52+
{{#allParams}}{{#required}}
53+
// verify the required parameter '{{paramName}}' is set
54+
if ({{paramName}} == null) {
55+
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
4156
}
42-
43-
{{#operation}}
44-
/**
45-
* {{summary}}
46-
* {{notes}}
47-
{{#allParams}} * @param {{paramName}} {{description}}
48-
{{/allParams}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
49-
*/
50-
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
51-
Object postBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}};
52-
{{#allParams}}{{#required}}
53-
// verify the required parameter '{{paramName}}' is set
54-
if ({{paramName}} == null) {
55-
throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{nickname}}");
56-
}
57-
{{/required}}{{/allParams}}
58-
59-
// create path and map variables
60-
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
61-
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
62-
63-
// query params
64-
Map
65-
<String, String> queryParams = new HashMap
66-
<String, String>();
67-
Map
68-
<String, String> headerParams = new HashMap
69-
<String, String>();
70-
Map
71-
<String, String> formParams = new HashMap
72-
<String, String>();
73-
74-
{{#queryParams}}if ({{paramName}} != null)
75-
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
76-
{{/queryParams}}
77-
78-
{{#headerParams}}if ({{paramName}} != null)
79-
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
80-
{{/headerParams}}
81-
82-
final String[] accepts = {
83-
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
84-
};
85-
final String accept = apiClient.selectHeaderAccept(accepts);
86-
87-
final String[] contentTypes = {
88-
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
89-
};
90-
final String contentType = apiClient.selectHeaderContentType(contentTypes);
91-
92-
if(contentType.startsWith("multipart/form-data")) {
93-
boolean hasFields = false;
94-
FormDataMultiPart mp = new FormDataMultiPart();
95-
{{#formParams}}{{#notFile}}
96-
if ({{paramName}} != null) {
97-
hasFields = true;
98-
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
99-
}
100-
{{/notFile}}{{#isFile}}
101-
if ({{paramName}} != null) {
102-
hasFields = true;
103-
mp.field("{{baseName}}", {{paramName}}.getName());
104-
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
105-
}
106-
{{/isFile}}{{/formParams}}
107-
if(hasFields)
57+
{{/required}}{{/allParams}}
58+
59+
// create path and map variables
60+
String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}
61+
.replaceAll("\\{" + "{{paramName}}" + "\\}", apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}};
62+
63+
// query params
64+
Map<String, String> queryParams = new HashMap<String, String>();
65+
Map<String, String> headerParams = new HashMap<String, String>();
66+
Map<String, String> formParams = new HashMap<String, String>();
67+
68+
{{#queryParams}}if ({{paramName}} != null)
69+
queryParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
70+
{{/queryParams}}
71+
72+
{{#headerParams}}if ({{paramName}} != null)
73+
headerParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));
74+
{{/headerParams}}
75+
76+
final String[] accepts = {
77+
{{#produces}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/produces}}
78+
};
79+
final String accept = apiClient.selectHeaderAccept(accepts);
80+
81+
final String[] contentTypes = {
82+
{{#consumes}}"{{mediaType}}"{{#hasMore}}, {{/hasMore}}{{/consumes}}
83+
};
84+
final String contentType = apiClient.selectHeaderContentType(contentTypes);
85+
86+
if(contentType.startsWith("multipart/form-data")) {
87+
boolean hasFields = false;
88+
FormDataMultiPart mp = new FormDataMultiPart();
89+
{{#formParams}}{{#notFile}}
90+
if ({{paramName}} != null) {
91+
hasFields = true;
92+
mp.field("{{baseName}}", apiClient.parameterToString({{paramName}}), MediaType.MULTIPART_FORM_DATA_TYPE);
93+
}
94+
{{/notFile}}{{#isFile}}
95+
if ({{paramName}} != null) {
96+
hasFields = true;
97+
mp.field("{{baseName}}", {{paramName}}.getName());
98+
mp.bodyPart(new FileDataBodyPart("{{baseName}}", {{paramName}}, MediaType.MULTIPART_FORM_DATA_TYPE));
99+
}
100+
{{/isFile}}{{/formParams}}
101+
if(hasFields)
108102
postBody = mp;
109-
}
110-
else {
111-
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
103+
}
104+
else {
105+
{{#formParams}}{{#notFile}}if ({{paramName}} != null)
112106
formParams.put("{{baseName}}", apiClient.parameterToString({{paramName}}));{{/notFile}}
113-
{{/formParams}}
114-
}
107+
{{/formParams}}
108+
}
115109

116-
try {
117-
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
118-
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
119-
if(response != null){
110+
try {
111+
String[] authNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
112+
String response = apiClient.invokeAPI(path, "{{httpMethod}}", queryParams, postBody, headerParams, formParams, accept, contentType, authNames);
113+
if(response != null){
120114
return {{#returnType}}({{{returnType}}}) apiClient.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
121-
}
122-
else {
115+
}
116+
else {
123117
return {{#returnType}}null{{/returnType}};
124-
}
125-
} catch (ApiException ex) {
126-
throw ex;
127-
}
128-
}
129-
{{/operation}}
118+
}
119+
} catch (ApiException ex) {
120+
throw ex;
130121
}
122+
}
123+
{{/operation}}
124+
}
131125
{{/operations}}

0 commit comments

Comments
 (0)