Skip to content

Commit d665903

Browse files
committed
Merge pull request #2149 from dhontecillas/master
support latest Retrofit 2 v2.0.0-beta4
2 parents 9cdd532 + 0fe8f7e commit d665903

File tree

15 files changed

+107
-144
lines changed

15 files changed

+107
-144
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public JavaClientCodegen() {
102102
supportedLibraries.put("jersey2", "HTTP client: Jersey client 2.6");
103103
supportedLibraries.put("okhttp-gson", "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1");
104104
supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.4.0. JSON processing: Gson 2.3.1 (Retrofit 1.9.0)");
105-
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta2). Enable the RxJava adapter using '-DuseRxJava=true'.");
105+
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 2.5.0. JSON processing: Gson 2.4 (Retrofit 2.0.0-beta4). Enable the RxJava adapter using '-DuseRxJava=true'.");
106106

107107
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
108108
library.setDefault(DEFAULT_LIBRARY);

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
1212

1313
import retrofit2.Converter;
1414
import retrofit2.Retrofit;
15-
import retrofit2.GsonConverterFactory;
16-
{{#useRxJava}}import retrofit2.RxJavaCallAdapterFactory;{{/useRxJava}}
15+
import retrofit2.converter.gson.GsonConverterFactory;
16+
{{#useRxJava}}import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;{{/useRxJava}}
1717

1818
import com.google.gson.Gson;
1919
import com.google.gson.GsonBuilder;
@@ -103,14 +103,14 @@ public class ApiClient {
103103
.setUsername(username)
104104
.setPassword(password);
105105
}
106-
106+
107107
public void createDefaultAdapter() {
108108
Gson gson = new GsonBuilder()
109109
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
110110
.create();
111111
112112
okClient = new OkHttpClient();
113-
113+
114114
String baseUrl = "{{basePath}}";
115115
if(!baseUrl.endsWith("/"))
116116
baseUrl = baseUrl + "/";
@@ -125,7 +125,7 @@ public class ApiClient {
125125

126126
public <S> S createService(Class<S> serviceClass) {
127127
return adapterBuilder.build().create(serviceClass);
128-
128+
129129
}
130130

131131
/**
@@ -203,7 +203,7 @@ public class ApiClient {
203203
}
204204
}
205205
}
206-
206+
207207
/**
208208
* Helper method to configure the oauth accessCode/implicit flow parameters
209209
* @param clientId
@@ -225,7 +225,7 @@ public class ApiClient {
225225
}
226226
}
227227
}
228-
228+
229229
/**
230230
* Configures a listener which is notified when a new access token is received.
231231
* @param accessTokenListener
@@ -272,7 +272,7 @@ public class ApiClient {
272272
public OkHttpClient getOkClient() {
273273
return okClient;
274274
}
275-
275+
276276
public void addAuthsToOkClient(OkHttpClient okClient) {
277277
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
278278
okClient.interceptors().add(apiAuthorization);
@@ -308,14 +308,14 @@ class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T>
308308
String returned = value.string();
309309
try {
310310
return gson.fromJson(returned, type);
311-
}
311+
}
312312
catch (JsonParseException e) {
313313
return (T) returned;
314-
}
314+
}
315315
}
316316
}
317317

318-
class GsonCustomConverterFactory extends Converter.Factory
318+
class GsonCustomConverterFactory extends Converter.Factory
319319
{
320320
public static GsonCustomConverterFactory create(Gson gson) {
321321
return new GsonCustomConverterFactory(gson);
@@ -339,8 +339,8 @@ class GsonCustomConverterFactory extends Converter.Factory
339339
}
340340

341341
@Override
342-
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
343-
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
342+
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
343+
return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
344344
}
345345
}
346346

modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/CollectionFormats.mustache

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import java.util.Arrays;
44
import java.util.List;
55

66
public class CollectionFormats {
7-
7+
88
public static class CSVParams {
99
1010
protected List<String> params;
11-
11+
1212
public CSVParams() {
1313
}
14-
14+
1515
public CSVParams(List<String> params) {
1616
this.params = params;
1717
}
18-
18+
1919
public CSVParams(String... params) {
2020
this.params = Arrays.asList(params);
2121
}
@@ -27,19 +27,19 @@ public class CollectionFormats {
2727
public void setParams(List<String> params) {
2828
this.params = params;
2929
}
30-
30+
3131
@Override
3232
public String toString() {
3333
return StringUtil.join(params.toArray(new String[0]), ",");
3434
}
35-
35+
3636
}
37-
37+
3838
public static class SSVParams extends CSVParams {
39-
39+
4040
public SSVParams() {
4141
}
42-
42+
4343
public SSVParams(List<String> params) {
4444
super(params);
4545
}
@@ -53,16 +53,16 @@ public class CollectionFormats {
5353
return StringUtil.join(params.toArray(new String[0]), " ");
5454
}
5555
}
56-
56+
5757
public static class TSVParams extends CSVParams {
58-
58+
5959
public TSVParams() {
6060
}
61-
61+
6262
public TSVParams(List<String> params) {
6363
super(params);
6464
}
65-
65+
6666
public TSVParams(String... params) {
6767
super(params);
6868
}
@@ -72,16 +72,16 @@ public class CollectionFormats {
7272
return StringUtil.join( params.toArray(new String[0]), "\t");
7373
}
7474
}
75-
75+
7676
public static class PIPESParams extends CSVParams {
77-
77+
7878
public PIPESParams() {
7979
}
80-
80+
8181
public PIPESParams(List<String> params) {
8282
super(params);
8383
}
84-
84+
8585
public PIPESParams(String... params) {
8686
super(params);
8787
}
@@ -91,5 +91,5 @@ public class CollectionFormats {
9191
return StringUtil.join(params.toArray(new String[0]), "|");
9292
}
9393
}
94-
94+
9595
}

modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,8 @@ if(hasProperty('target') && target == 'android') {
9090
}
9191

9292
ext {
93-
okhttp_version = "3.0.1"
9493
oltu_version = "1.0.0"
95-
retrofit_version = "2.0.0-beta3"
94+
retrofit_version = "2.0.0-beta4"
9695
gson_version = "2.4"
9796
swagger_annotations_version = "1.5.0"
9897
junit_version = "4.12"
@@ -103,8 +102,6 @@ ext {
103102
}
104103

105104
dependencies {
106-
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
107-
108105
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
109106
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
110107
{{#useRxJava}}
@@ -113,7 +110,6 @@ dependencies {
113110
{{/useRxJava}}
114111
{{^useRxJava}}{{/useRxJava}}
115112

116-
compile "com.google.code.gson:gson:$gson_version"
117113
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
118114
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
119115

modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
</dependencies>
162162
<properties>
163163
<swagger-annotations-version>1.5.0</swagger-annotations-version>
164-
<retrofit-version>2.0.0-beta3</retrofit-version>
164+
<retrofit-version>2.0.0-beta4</retrofit-version>
165165
{{#useRxJava}}<rxjava-version>1.0.16</rxjava-version>{{/useRxJava}}
166166
<okhttp-version>3.0.1</okhttp-version>
167167
<gson-version>2.4</gson-version>

samples/client/petstore/java/retrofit2/build.gradle

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,19 @@ if(hasProperty('target') && target == 'android') {
9090
}
9191

9292
ext {
93-
okhttp_version = "3.0.1"
9493
oltu_version = "1.0.0"
95-
retrofit_version = "2.0.0-beta3"
94+
retrofit_version = "2.0.0-beta4"
9695
gson_version = "2.4"
9796
swagger_annotations_version = "1.5.0"
9897
junit_version = "4.12"
9998

10099
}
101100

102101
dependencies {
103-
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
104-
105102
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
106103
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
107104

108105

109-
compile "com.google.code.gson:gson:$gson_version"
110106
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
111107
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
112108

samples/client/petstore/java/retrofit2/pom.xml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,11 @@
123123
<artifactId>converter-gson</artifactId>
124124
<version>${retrofit-version}</version>
125125
</dependency>
126-
<dependency>
127-
<groupId>com.google.code.gson</groupId>
128-
<artifactId>gson</artifactId>
129-
<version>${gson-version}</version>
130-
</dependency>
131126
<dependency>
132127
<groupId>org.apache.oltu.oauth2</groupId>
133128
<artifactId>org.apache.oltu.oauth2.client</artifactId>
134129
<version>${oltu-version}</version>
135130
</dependency>
136-
<dependency>
137-
<groupId>com.squareup.okhttp3</groupId>
138-
<artifactId>okhttp</artifactId>
139-
<version>${okhttp-version}</version>
140-
</dependency>
141131

142132

143133
<!-- test dependencies -->
@@ -150,10 +140,7 @@
150140
</dependencies>
151141
<properties>
152142
<swagger-annotations-version>1.5.0</swagger-annotations-version>
153-
<retrofit-version>2.0.0-beta3</retrofit-version>
154-
155-
<okhttp-version>3.0.1</okhttp-version>
156-
<gson-version>2.4</gson-version>
143+
<retrofit-version>2.0.0-beta4</retrofit-version>
157144
<oltu-version>1.0.0</oltu-version>
158145
<maven-plugin-version>1.0.0</maven-plugin-version>
159146
<junit-version>4.12</junit-version>

samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import retrofit2.Converter;
1414
import retrofit2.Retrofit;
15-
import retrofit2.GsonConverterFactory;
15+
import retrofit2.converter.gson.GsonConverterFactory;
1616

1717

1818
import com.google.gson.Gson;
@@ -46,10 +46,10 @@ public ApiClient(String[] authNames) {
4646
this();
4747
for(String authName : authNames) {
4848
Interceptor auth;
49-
if (authName == "petstore_auth") {
50-
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
51-
} else if (authName == "api_key") {
49+
if (authName == "api_key") {
5250
auth = new ApiKeyAuth("header", "api_key");
51+
} else if (authName == "petstore_auth") {
52+
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
5353
} else {
5454
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
5555
}
@@ -102,14 +102,14 @@ public ApiClient(String authName, String clientId, String secret, String usernam
102102
.setUsername(username)
103103
.setPassword(password);
104104
}
105-
105+
106106
public void createDefaultAdapter() {
107107
Gson gson = new GsonBuilder()
108108
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
109109
.create();
110110

111111
okClient = new OkHttpClient();
112-
112+
113113
String baseUrl = "http://petstore.swagger.io/v2";
114114
if(!baseUrl.endsWith("/"))
115115
baseUrl = baseUrl + "/";
@@ -124,7 +124,7 @@ public void createDefaultAdapter() {
124124

125125
public <S> S createService(Class<S> serviceClass) {
126126
return adapterBuilder.build().create(serviceClass);
127-
127+
128128
}
129129

130130
/**
@@ -202,7 +202,7 @@ public void setAccessToken(String accessToken) {
202202
}
203203
}
204204
}
205-
205+
206206
/**
207207
* Helper method to configure the oauth accessCode/implicit flow parameters
208208
* @param clientId
@@ -224,7 +224,7 @@ public void configureAuthorizationFlow(String clientId, String clientSecret, Str
224224
}
225225
}
226226
}
227-
227+
228228
/**
229229
* Configures a listener which is notified when a new access token is received.
230230
* @param accessTokenListener
@@ -271,7 +271,7 @@ public void setAdapterBuilder(Retrofit.Builder adapterBuilder) {
271271
public OkHttpClient getOkClient() {
272272
return okClient;
273273
}
274-
274+
275275
public void addAuthsToOkClient(OkHttpClient okClient) {
276276
for(Interceptor apiAuthorization : apiAuthorizations.values()) {
277277
okClient.interceptors().add(apiAuthorization);
@@ -307,14 +307,14 @@ class GsonResponseBodyConverterToString<T> implements Converter<ResponseBody, T>
307307
String returned = value.string();
308308
try {
309309
return gson.fromJson(returned, type);
310-
}
310+
}
311311
catch (JsonParseException e) {
312312
return (T) returned;
313-
}
313+
}
314314
}
315315
}
316316

317-
class GsonCustomConverterFactory extends Converter.Factory
317+
class GsonCustomConverterFactory extends Converter.Factory
318318
{
319319
public static GsonCustomConverterFactory create(Gson gson) {
320320
return new GsonCustomConverterFactory(gson);
@@ -338,8 +338,8 @@ private GsonCustomConverterFactory(Gson gson) {
338338
}
339339

340340
@Override
341-
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
342-
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
341+
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
342+
return gsonConverterFactory.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
343343
}
344344
}
345345

0 commit comments

Comments
 (0)