mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-11 02:12:45 +00:00
Merge pull request #2019 from ergon/feature/use-retrofit-beta3
Use retrofit2-beta3 and it's dendencies in retrofit2 clients
This commit is contained in:
@@ -10,18 +10,18 @@ import java.util.Map;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder;
|
||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||
|
||||
import retrofit.Converter;
|
||||
import retrofit.Retrofit;
|
||||
import retrofit.GsonConverterFactory;
|
||||
{{#useRxJava}}import retrofit.RxJavaCallAdapterFactory;{{/useRxJava}}
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.GsonConverterFactory;
|
||||
{{#useRxJava}}import retrofit2.RxJavaCallAdapterFactory;{{/useRxJava}}
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.ResponseBody;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
|
||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||
@@ -284,7 +284,7 @@ public class ApiClient {
|
||||
* @param okClient
|
||||
*/
|
||||
public void configureFromOkclient(OkHttpClient okClient) {
|
||||
OkHttpClient clone = okClient.clone();
|
||||
OkHttpClient clone = okClient.newBuilder().build();
|
||||
addAuthsToOkClient(clone);
|
||||
adapterBuilder.client(clone);
|
||||
}
|
||||
@@ -330,17 +330,17 @@ class GsonCustomConverterFactory extends Converter.Factory
|
||||
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
||||
if(type.equals(String.class))
|
||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||
else
|
||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
||||
}
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
if(type.equals(String.class))
|
||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||
else
|
||||
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
||||
}
|
||||
@Override
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ package {{package}};
|
||||
import {{invokerPackage}}.CollectionFormats.*;
|
||||
|
||||
{{#useRxJava}}import rx.Observable;{{/useRxJava}}
|
||||
{{^useRxJava}}import retrofit.Call;{{/useRxJava}}
|
||||
import retrofit.http.*;
|
||||
{{^useRxJava}}import retrofit2.Call;{{/useRxJava}}
|
||||
import retrofit2.http.*;
|
||||
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
{{#imports}}import {{import}};
|
||||
{{/imports}}
|
||||
|
||||
@@ -4,9 +4,9 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class ApiKeyAuth implements Interceptor {
|
||||
private final String location;
|
||||
@@ -41,18 +41,18 @@ public class ApiKeyAuth implements Interceptor {
|
||||
Request request = chain.request();
|
||||
|
||||
if (location == "query") {
|
||||
String newQuery = request.uri().getQuery();
|
||||
String newQuery = request.url().uri().getQuery();
|
||||
paramValue = paramName + "=" + apiKey;
|
||||
if (newQuery == null) {
|
||||
newQuery = paramValue;
|
||||
} else {
|
||||
newQuery += "&" + paramValue;
|
||||
newQuery += "&" + paramValue;
|
||||
}
|
||||
|
||||
URI newUri;
|
||||
try {
|
||||
newUri = new URI(request.uri().getScheme(), request.uri().getAuthority(),
|
||||
request.uri().getPath(), newQuery, request.uri().getFragment());
|
||||
newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(),
|
||||
request.url().uri().getPath(), newQuery, request.url().uri().getFragment());
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package {{invokerPackage}}.auth;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.squareup.okhttp.Credentials;
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Response;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.Credentials;
|
||||
|
||||
public class HttpBasicAuth implements Interceptor {
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@ import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
import org.apache.oltu.oauth2.common.message.types.GrantType;
|
||||
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
||||
|
||||
import com.squareup.okhttp.Interceptor;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.Request.Builder;
|
||||
import com.squareup.okhttp.Response;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Request.Builder;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class OAuth implements Interceptor {
|
||||
|
||||
@@ -90,9 +90,9 @@ public class OAuth implements Interceptor {
|
||||
|
||||
String requestAccessToken = new String(getAccessToken());
|
||||
try {
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
||||
.setAccessToken(requestAccessToken)
|
||||
.buildHeaderMessage();
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||
.setAccessToken(requestAccessToken)
|
||||
.buildHeaderMessage();
|
||||
} catch (OAuthSystemException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,14 @@ import org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthProblemException;
|
||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.Request;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import com.squareup.okhttp.Response;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Request.Builder;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
|
||||
public class OAuthOkHttpClient implements HttpClient {
|
||||
|
||||
@@ -74,8 +74,8 @@ if(hasProperty('target') && target == 'android') {
|
||||
apply plugin: 'java'
|
||||
apply plugin: 'maven'
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||
targetCompatibility = JavaVersion.VERSION_1_7
|
||||
|
||||
install {
|
||||
repositories.mavenInstaller {
|
||||
@@ -90,25 +90,25 @@ targetCompatibility = JavaVersion.VERSION_1_7
|
||||
}
|
||||
|
||||
ext {
|
||||
okhttp_version = "2.5.0"
|
||||
okhttp_version = "3.0.1"
|
||||
oltu_version = "1.0.0"
|
||||
retrofit_version = "2.0.0-beta2"
|
||||
retrofit_version = "2.0.0-beta3"
|
||||
gson_version = "2.4"
|
||||
swagger_annotations_version = "1.5.0"
|
||||
junit_version = "4.12"
|
||||
{{#useRxJava}}
|
||||
rx_java_version = "1.0.15"
|
||||
rx_java_version = "1.0.16"
|
||||
{{/useRxJava}}
|
||||
{{^useRxJava}}{{/useRxJava}}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.squareup.okhttp:okhttp:$okhttp_version"
|
||||
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
|
||||
|
||||
compile "com.squareup.retrofit:retrofit:$retrofit_version"
|
||||
compile "com.squareup.retrofit:converter-gson:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||
{{#useRxJava}}
|
||||
compile "com.squareup.retrofit:adapter-rxjava:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
|
||||
compile "io.reactivex:rxjava:$rx_java_version"
|
||||
{{/useRxJava}}
|
||||
{{^useRxJava}}{{/useRxJava}}
|
||||
|
||||
@@ -114,12 +114,12 @@
|
||||
<version>${swagger-annotations-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit</groupId>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>retrofit</artifactId>
|
||||
<version>${retrofit-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit</groupId>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>converter-gson</artifactId>
|
||||
<version>${retrofit-version}</version>
|
||||
</dependency>
|
||||
@@ -134,7 +134,7 @@
|
||||
<version>${oltu-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp-version}</version>
|
||||
</dependency>
|
||||
@@ -145,7 +145,7 @@
|
||||
<version>${rxjava-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit</groupId>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>adapter-rxjava</artifactId>
|
||||
<version>${retrofit-version}</version>
|
||||
</dependency>
|
||||
@@ -161,9 +161,9 @@
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
||||
{{#useRxJava}}<rxjava-version>1.0.15</rxjava-version>{{/useRxJava}}
|
||||
<okhttp-version>2.5.0</okhttp-version>
|
||||
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||
{{#useRxJava}}<rxjava-version>1.0.16</rxjava-version>{{/useRxJava}}
|
||||
<okhttp-version>3.0.1</okhttp-version>
|
||||
<gson-version>2.4</gson-version>
|
||||
<oltu-version>1.0.0</oltu-version>
|
||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||
|
||||
Reference in New Issue
Block a user