forked from loafle/openapi-generator-original
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:
commit
cd0c8728b7
@ -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);
|
||||
}
|
||||
@ -331,16 +331,16 @@ class GsonCustomConverterFactory extends Converter.Factory
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
if(type.equals(String.class))
|
||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||
else
|
||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
||||
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
||||
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,7 +41,7 @@ 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;
|
||||
@ -51,8 +51,8 @@ public class ApiKeyAuth implements Interceptor {
|
||||
|
||||
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,7 +90,7 @@ public class OAuth implements Interceptor {
|
||||
|
||||
String requestAccessToken = new String(getAccessToken());
|
||||
try {
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||
.setAccessToken(requestAccessToken)
|
||||
.buildHeaderMessage();
|
||||
} catch (OAuthSystemException 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>
|
||||
|
@ -1,3 +1,6 @@
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
group = 'io.swagger'
|
||||
version = '1.0.0'
|
||||
|
||||
@ -87,20 +90,25 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
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"
|
||||
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile "com.squareup.okhttp:okhttp:$okhttp_version"
|
||||
compile "com.squareup.retrofit:retrofit:$retrofit_version"
|
||||
compile "com.squareup.okhttp3:okhttp:$okhttp_version"
|
||||
|
||||
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||
|
||||
|
||||
compile "com.google.code.gson:gson:$gson_version"
|
||||
compile "com.squareup.retrofit:converter-gson:$retrofit_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"
|
||||
}
|
||||
|
@ -100,8 +100,9 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>
|
||||
1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@ -113,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>
|
||||
@ -133,11 +134,12 @@
|
||||
<version>${oltu-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp</groupId>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>${okhttp-version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- test dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@ -148,8 +150,9 @@
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
||||
<okhttp-version>2.5.0</okhttp-version>
|
||||
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||
|
||||
<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>
|
||||
|
@ -10,17 +10,19 @@ 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;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.GsonConverterFactory;
|
||||
|
||||
|
||||
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 io.swagger.client.auth.HttpBasicAuth;
|
||||
import io.swagger.client.auth.ApiKeyAuth;
|
||||
@ -44,10 +46,10 @@ public class ApiClient {
|
||||
this();
|
||||
for(String authName : authNames) {
|
||||
Interceptor auth;
|
||||
if (authName == "api_key") {
|
||||
auth = new ApiKeyAuth("header", "api_key");
|
||||
} else if (authName == "petstore_auth") {
|
||||
if (authName == "petstore_auth") {
|
||||
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
|
||||
} else if (authName == "api_key") {
|
||||
auth = new ApiKeyAuth("header", "api_key");
|
||||
} else {
|
||||
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
||||
}
|
||||
@ -116,6 +118,7 @@ public class ApiClient {
|
||||
.Builder()
|
||||
.baseUrl(baseUrl)
|
||||
.client(okClient)
|
||||
|
||||
.addConverterFactory(GsonCustomConverterFactory.create(gson));
|
||||
}
|
||||
|
||||
@ -280,7 +283,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);
|
||||
}
|
||||
@ -327,16 +330,16 @@ class GsonCustomConverterFactory extends Converter.Factory
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
if(type.equals(String.class))
|
||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||
else
|
||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
||||
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.swagger.client;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-05T14:39:22.425+08:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-02T15:33:05.826+01:00")
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
|
@ -2,9 +2,11 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import retrofit.Call;
|
||||
import retrofit.http.*;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
@ -124,4 +126,30 @@ public interface PetApi {
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array return by 'Find pet by ID'
|
||||
* Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
|
||||
* @param petId ID of pet that needs to be fetched
|
||||
* @return Call<byte[]>
|
||||
*/
|
||||
|
||||
@GET("pet/{petId}?testing_byte_array=true")
|
||||
Call<byte[]> getPetByIdWithByteArray(
|
||||
@Path("petId") Long petId
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Fake endpoint to test byte array in body parameter for adding a new pet to the store
|
||||
*
|
||||
* @param body Pet object in the form of byte array
|
||||
* @return Call<Void>
|
||||
*/
|
||||
|
||||
@POST("pet?testing_byte_array=true")
|
||||
Call<Void> addPetUsingByteArray(
|
||||
@Body byte[] body
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,11 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import retrofit.Call;
|
||||
import retrofit.http.*;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
import io.swagger.client.model.Order;
|
||||
|
@ -2,9 +2,11 @@ package io.swagger.client.api;
|
||||
|
||||
import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import retrofit.Call;
|
||||
import retrofit.http.*;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import io.swagger.client.model.User;
|
||||
import java.util.*;
|
||||
|
@ -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,7 +41,7 @@ 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;
|
||||
@ -51,8 +51,8 @@ public class ApiKeyAuth implements Interceptor {
|
||||
|
||||
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 io.swagger.client.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,7 +90,7 @@ public class OAuth implements Interceptor {
|
||||
|
||||
String requestAccessToken = new String(getAccessToken());
|
||||
try {
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||
.setAccessToken(requestAccessToken)
|
||||
.buildHeaderMessage();
|
||||
} catch (OAuthSystemException 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 {
|
||||
|
@ -15,10 +15,10 @@ import java.util.List;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import retrofit.Response;
|
||||
import retrofit2.Response;
|
||||
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@ -141,7 +141,7 @@ public class PetApiTest {
|
||||
writer.write("Hello world!");
|
||||
writer.close();
|
||||
|
||||
api.uploadFile(pet.getId(), "a test file", RequestBody.create(MediaType.parse("text/plain"), file)).execute();
|
||||
api.uploadFile(pet.getId(), null, RequestBody.create(MediaType.parse("text/plain"), file)).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import retrofit.Response;
|
||||
import retrofit2.Response;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class StoreApiTest {
|
||||
|
@ -1,3 +1,6 @@
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'eclipse'
|
||||
|
||||
group = 'io.swagger'
|
||||
version = '1.0.0'
|
||||
|
||||
@ -87,22 +90,22 @@ if(hasProperty('target') && target == 'android') {
|
||||
}
|
||||
|
||||
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"
|
||||
rx_java_version = "1.0.15"
|
||||
rx_java_version = "1.0.16"
|
||||
|
||||
}
|
||||
|
||||
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.retrofit:adapter-rxjava:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
|
||||
compile "io.reactivex:rxjava:$rx_java_version"
|
||||
|
||||
|
||||
|
@ -101,8 +101,7 @@
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>
|
||||
1.7
|
||||
</source>
|
||||
1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
@ -115,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>
|
||||
@ -135,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>
|
||||
@ -146,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>
|
||||
@ -162,9 +161,9 @@
|
||||
</dependencies>
|
||||
<properties>
|
||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
||||
<rxjava-version>1.0.15</rxjava-version>
|
||||
<okhttp-version>2.5.0</okhttp-version>
|
||||
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||
<rxjava-version>1.0.16</rxjava-version>
|
||||
<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>
|
||||
|
@ -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;
|
||||
import retrofit.RxJavaCallAdapterFactory;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.GsonConverterFactory;
|
||||
import retrofit2.RxJavaCallAdapterFactory;
|
||||
|
||||
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 io.swagger.client.auth.HttpBasicAuth;
|
||||
@ -283,7 +283,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,16 +330,16 @@ class GsonCustomConverterFactory extends Converter.Factory
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
if(type.equals(String.class))
|
||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||
else
|
||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
||||
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package io.swagger.client;
|
||||
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-01-22T16:57:22.418+01:00")
|
||||
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2016-02-02T15:33:07.490+01:00")
|
||||
public class StringUtil {
|
||||
/**
|
||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
||||
|
@ -4,9 +4,9 @@ import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import retrofit.http.*;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import io.swagger.client.model.Pet;
|
||||
import java.io.File;
|
||||
|
@ -4,9 +4,9 @@ import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import retrofit.http.*;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import java.util.Map;
|
||||
import io.swagger.client.model.Order;
|
||||
|
@ -4,9 +4,9 @@ import io.swagger.client.CollectionFormats.*;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import retrofit.http.*;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import io.swagger.client.model.User;
|
||||
import java.util.*;
|
||||
|
@ -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,7 +41,7 @@ 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;
|
||||
@ -51,8 +51,8 @@ public class ApiKeyAuth implements Interceptor {
|
||||
|
||||
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 io.swagger.client.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,7 +90,7 @@ public class OAuth implements Interceptor {
|
||||
|
||||
String requestAccessToken = new String(getAccessToken());
|
||||
try {
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
||||
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||
.setAccessToken(requestAccessToken)
|
||||
.buildHeaderMessage();
|
||||
} catch (OAuthSystemException 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 {
|
||||
|
@ -13,8 +13,8 @@ import java.util.List;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import com.squareup.okhttp.MediaType;
|
||||
import com.squareup.okhttp.RequestBody;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
@ -8,7 +8,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.*;
|
||||
|
||||
import retrofit.Response;
|
||||
import retrofit2.Response;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user