forked from loafle/openapi-generator-original
Add 'useRxJava' option to retrofit2 java client generator
This still uses retrofit 2.0.0-beta2 because the api in beta3 has changed and the package has been renamed to retrofit2.* Change retrofit-rx to be a library option
This commit is contained in:
@@ -13,6 +13,7 @@ import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuil
|
||||
import retrofit.Converter;
|
||||
import retrofit.Retrofit;
|
||||
import retrofit.GsonConverterFactory;
|
||||
{{#useRxJava}}import retrofit.RxJavaCallAdapterFactory;{{/useRxJava}}
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
@@ -22,6 +23,7 @@ import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
|
||||
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||
import {{invokerPackage}}.auth.OAuth;
|
||||
@@ -117,6 +119,7 @@ public class ApiClient {
|
||||
.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.client(okClient)
|
||||
{{#useRxJava}}.addCallAdapterFactory(RxJavaCallAdapterFactory.create()){{/useRxJava}}
|
||||
.addConverterFactory(GsonCustomConverterFactory.create(gson));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ package {{package}};
|
||||
|
||||
import {{invokerPackage}}.CollectionFormats.*;
|
||||
|
||||
import retrofit.Call;
|
||||
{{#useRxJava}}import rx.Observable;{{/useRxJava}}
|
||||
{{^useRxJava}}import retrofit.Call;{{/useRxJava}}
|
||||
import retrofit.http.*;
|
||||
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
@@ -25,7 +27,7 @@ public interface {{classname}} {
|
||||
{{#formParams}}{{#-first}}
|
||||
{{#isMultipart}}@Multipart{{/isMultipart}}{{^isMultipart}}@FormUrlEncoded{{/isMultipart}}{{/-first}}{{/formParams}}
|
||||
@{{httpMethod}}("{{path}}")
|
||||
Call<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}({{^allParams}});{{/allParams}}
|
||||
{{#useRxJava}}Observable{{/useRxJava}}{{^useRxJava}}Call{{/useRxJava}}<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Object{{/returnType}}> {{operationId}}({{^allParams}});{{/allParams}}
|
||||
{{#allParams}}{{>libraries/retrofit2/queryParams}}{{>libraries/retrofit2/pathParams}}{{>libraries/retrofit2/headerParams}}{{>libraries/retrofit2/bodyParams}}{{>libraries/retrofit2/formParams}}{{#hasMore}}, {{/hasMore}}{{^hasMore}}
|
||||
);{{/hasMore}}{{/allParams}}
|
||||
|
||||
|
||||
@@ -93,14 +93,26 @@ ext {
|
||||
gson_version = "2.4"
|
||||
swagger_annotations_version = "1.5.0"
|
||||
junit_version = "4.12"
|
||||
{{#useRxJava}}
|
||||
rx_java_version = "1.0.15"
|
||||
{{/useRxJava}}
|
||||
{{^useRxJava}}{{/useRxJava}}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.squareup.okhttp:okhttp:$okhttp_version"
|
||||
|
||||
compile "com.squareup.retrofit:retrofit:$retrofit_version"
|
||||
compile "com.google.code.gson:gson:$gson_version"
|
||||
compile "com.squareup.retrofit:converter-gson:$retrofit_version"
|
||||
{{#useRxJava}}
|
||||
compile "com.squareup.retrofit:adapter-rxjava:$retrofit_version"
|
||||
compile "io.reactivex:rxjava:$rx_java_version"
|
||||
{{/useRxJava}}
|
||||
{{^useRxJava}}{{/useRxJava}}
|
||||
|
||||
compile "com.google.code.gson:gson:$gson_version"
|
||||
compile "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
|
||||
|
||||
testCompile "junit:junit:$junit_version"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user