Skip to content

Commit b88fcdb

Browse files
committed
fixed errors found on jersey3 template and added missed template for resteasy-eap generator
1 parent 9e3a107 commit b88fcdb

File tree

8 files changed

+352
-13
lines changed

8 files changed

+352
-13
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public JavaClientCodegen() {
8484
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.4. JSON processing: Jackson 2.11.4. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
8585
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.11.4");
8686
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.29.1. JSON processing: Jackson 2.11.4");
87+
supportedLibraries.put("jersey3", "HTTP client: Jersey client 3.0.10. JSON processing: Jackson 2.10.2");
8788
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
8889
supportedLibraries.put("okhttp4-gson", "HTTP client: OkHttp 4.10.0. JSON processing: Gson 2.8.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
8990
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.7.5. JSON processing: Gson 2.3.1 (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.");
@@ -123,6 +124,10 @@ public void processOpts() {
123124
if (RETROFIT_1.equalsIgnoreCase(library)) {
124125
dateLibrary = "joda";
125126
}
127+
if ("jersey3".equalsIgnoreCase(library)) {
128+
dateLibrary = "java8";
129+
additionalProperties.put(JAKARTA, true);
130+
}
126131

127132
super.processOpts();
128133

@@ -252,7 +257,7 @@ public void processOpts() {
252257
if ("retrofit2".equals(getLibrary()) && !usePlayWS) {
253258
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
254259
}
255-
} else if ("jersey2".equals(getLibrary())) {
260+
} else if ("jersey3".equals(getLibrary()) || "jersey2".equals(getLibrary())) {
256261
supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java"));
257262
supportingFiles.add(new SupportingFile("ApiResponse.mustache", invokerFolder, "ApiResponse.java"));
258263
additionalProperties.put("jackson", "true");

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ public class ApiClient {
8080
setUserAgent("{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}Swagger-Codegen/{{{artifactVersion}}}/java{{/httpUserAgent}}");
8181
8282
// Setup authentications (key: authentication name, value: authentication).
83-
authentications = new HashMap<>();{{#authMethods}}{{#is this 'basic'}}
84-
authentications.put("{{name}}", new HttpBasicAuth());{{/is}}{{#is this 'api-key'}}
85-
authentications.put("{{name}}", new ApiKeyAuth({{#is this 'key-in-header'}}"header"{{/is}}{{#isNot this 'key-in-header'}}"query"{{/isNot}}, "{{keyParamName}}"));{{/is}}{{#is this 'oauth'}}
86-
authentications.put("{{name}}", new OAuth());{{/is}}{{#is this 'bearer'}}
87-
authentications.put("{{name}}", new OAuth());{{/is}}{{/authMethods}}
83+
authentications = new HashMap<String, Authentication>();{{#authMethods}}{{#isBasic}}
84+
authentications.put("{{name}}", new HttpBasicAuth());{{/isBasic}}{{#isApiKey}}
85+
authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{^isKeyInHeader}}"query"{{/isKeyInHeader}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}}
86+
authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}}
8887
// Prevent the authentications from being modified.
8988
authentications = Collections.unmodifiableMap(authentications);
9089
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{{>licenseInfo}}
2+
3+
package {{invokerPackage}};
4+
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
/**
9+
* API response returned by API call.
10+
*
11+
* @param <T> The type of data that is deserialized from response body
12+
*/
13+
public class ApiResponse<T> {
14+
private final int statusCode;
15+
private final Map<String, List<String>> headers;
16+
private final T data;
17+
18+
/**
19+
* @param statusCode The status code of HTTP response
20+
* @param headers The headers of HTTP response
21+
*/
22+
public ApiResponse(int statusCode, Map<String, List<String>> headers) {
23+
this(statusCode, headers, null);
24+
}
25+
26+
/**
27+
* @param statusCode The status code of HTTP response
28+
* @param headers The headers of HTTP response
29+
* @param data The object deserialized from response bod
30+
*/
31+
public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
32+
this.statusCode = statusCode;
33+
this.headers = headers;
34+
this.data = data;
35+
}
36+
37+
public int getStatusCode() {
38+
return statusCode;
39+
}
40+
41+
public Map<String, List<String>> getHeaders() {
42+
return headers;
43+
}
44+
45+
public T getData() {
46+
return data;
47+
}
48+
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class {{classname}} {
3737
}
3838

3939
{{#operation}}
40-
{{#contents}}
4140
/**
4241
* {{summary}}
4342
* {{notes}}
@@ -59,7 +58,7 @@ public class {{classname}} {
5958
{{#isDeprecated}}
6059
@Deprecated
6160
{{/isDeprecated}}
62-
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#has this 'more'}}, {{/has}}{{/allParams}}) throws ApiException {
61+
public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
6362
Object {{localVariablePrefix}}localVarPostBody = {{^isForm}}{{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}{{/isForm}}{{#isForm}}null{{/isForm}};
6463
{{#allParams}}
6564
{{#required}}
@@ -103,7 +102,7 @@ public class {{classname}} {
103102
};
104103
final String {{localVariablePrefix}}localVarContentType = {{localVariablePrefix}}apiClient.selectHeaderContentType({{localVariablePrefix}}localVarContentTypes);
105104

106-
String[] {{localVariablePrefix}}localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{#has this 'more'}}, {{/has}}{{/authMethods}} };
105+
String[] {{localVariablePrefix}}localVarAuthNames = new String[] { {{#authMethods}}"{{name}}"{{#hasMore}}, {{/hasMore}}{{/authMethods}} };
107106

108107
{{#returnType}}
109108
GenericType<{{{returnType}}}> {{localVariablePrefix}}localVarReturnType = new GenericType<{{{returnType}}}>() {};
@@ -112,7 +111,6 @@ public class {{classname}} {
112111
{{localVariablePrefix}}apiClient.invokeAPI({{localVariablePrefix}}localVarPath, "{{httpMethod}}", {{localVariablePrefix}}localVarQueryParams, {{localVariablePrefix}}localVarPostBody, {{localVariablePrefix}}localVarHeaderParams, {{localVariablePrefix}}localVarFormParams, {{localVariablePrefix}}localVarAccept, {{localVariablePrefix}}localVarContentType, {{localVariablePrefix}}localVarAuthNames, null);
113112
{{/returnType}}
114113
}
115-
{{/contents}}
116114
{{/operation}}
117115
}
118116
{{/operations}}

0 commit comments

Comments
 (0)