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.AuthenticationRequestBuilder;
|
||||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||||
|
|
||||||
import retrofit.Converter;
|
import retrofit2.Converter;
|
||||||
import retrofit.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit.GsonConverterFactory;
|
import retrofit2.GsonConverterFactory;
|
||||||
{{#useRxJava}}import retrofit.RxJavaCallAdapterFactory;{{/useRxJava}}
|
{{#useRxJava}}import retrofit2.RxJavaCallAdapterFactory;{{/useRxJava}}
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import com.squareup.okhttp.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
@ -284,7 +284,7 @@ public class ApiClient {
|
|||||||
* @param okClient
|
* @param okClient
|
||||||
*/
|
*/
|
||||||
public void configureFromOkclient(OkHttpClient okClient) {
|
public void configureFromOkclient(OkHttpClient okClient) {
|
||||||
OkHttpClient clone = okClient.clone();
|
OkHttpClient clone = okClient.newBuilder().build();
|
||||||
addAuthsToOkClient(clone);
|
addAuthsToOkClient(clone);
|
||||||
adapterBuilder.client(clone);
|
adapterBuilder.client(clone);
|
||||||
}
|
}
|
||||||
@ -330,17 +330,17 @@ class GsonCustomConverterFactory extends Converter.Factory
|
|||||||
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
if(type.equals(String.class))
|
if(type.equals(String.class))
|
||||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||||
else
|
else
|
||||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,10 @@ package {{package}};
|
|||||||
import {{invokerPackage}}.CollectionFormats.*;
|
import {{invokerPackage}}.CollectionFormats.*;
|
||||||
|
|
||||||
{{#useRxJava}}import rx.Observable;{{/useRxJava}}
|
{{#useRxJava}}import rx.Observable;{{/useRxJava}}
|
||||||
{{^useRxJava}}import retrofit.Call;{{/useRxJava}}
|
{{^useRxJava}}import retrofit2.Call;{{/useRxJava}}
|
||||||
import retrofit.http.*;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
{{#imports}}import {{import}};
|
{{#imports}}import {{import}};
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class ApiKeyAuth implements Interceptor {
|
public class ApiKeyAuth implements Interceptor {
|
||||||
private final String location;
|
private final String location;
|
||||||
@ -41,18 +41,18 @@ public class ApiKeyAuth implements Interceptor {
|
|||||||
Request request = chain.request();
|
Request request = chain.request();
|
||||||
|
|
||||||
if (location == "query") {
|
if (location == "query") {
|
||||||
String newQuery = request.uri().getQuery();
|
String newQuery = request.url().uri().getQuery();
|
||||||
paramValue = paramName + "=" + apiKey;
|
paramValue = paramName + "=" + apiKey;
|
||||||
if (newQuery == null) {
|
if (newQuery == null) {
|
||||||
newQuery = paramValue;
|
newQuery = paramValue;
|
||||||
} else {
|
} else {
|
||||||
newQuery += "&" + paramValue;
|
newQuery += "&" + paramValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
URI newUri;
|
URI newUri;
|
||||||
try {
|
try {
|
||||||
newUri = new URI(request.uri().getScheme(), request.uri().getAuthority(),
|
newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(),
|
||||||
request.uri().getPath(), newQuery, request.uri().getFragment());
|
request.url().uri().getPath(), newQuery, request.url().uri().getFragment());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package {{invokerPackage}}.auth;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Credentials;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.Credentials;
|
||||||
|
|
||||||
public class HttpBasicAuth implements Interceptor {
|
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.message.types.GrantType;
|
||||||
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Request.Builder;
|
import okhttp3.Request.Builder;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class OAuth implements Interceptor {
|
public class OAuth implements Interceptor {
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ public class OAuth implements Interceptor {
|
|||||||
|
|
||||||
String requestAccessToken = new String(getAccessToken());
|
String requestAccessToken = new String(getAccessToken());
|
||||||
try {
|
try {
|
||||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||||
.setAccessToken(requestAccessToken)
|
.setAccessToken(requestAccessToken)
|
||||||
.buildHeaderMessage();
|
.buildHeaderMessage();
|
||||||
} catch (OAuthSystemException e) {
|
} catch (OAuthSystemException e) {
|
||||||
throw new IOException(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.OAuthProblemException;
|
||||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||||
|
|
||||||
import com.squareup.okhttp.MediaType;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Request.Builder;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
|
|
||||||
public class OAuthOkHttpClient implements HttpClient {
|
public class OAuthOkHttpClient implements HttpClient {
|
||||||
|
@ -74,8 +74,8 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_7
|
||||||
|
|
||||||
install {
|
install {
|
||||||
repositories.mavenInstaller {
|
repositories.mavenInstaller {
|
||||||
@ -90,25 +90,25 @@ targetCompatibility = JavaVersion.VERSION_1_7
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
okhttp_version = "2.5.0"
|
okhttp_version = "3.0.1"
|
||||||
oltu_version = "1.0.0"
|
oltu_version = "1.0.0"
|
||||||
retrofit_version = "2.0.0-beta2"
|
retrofit_version = "2.0.0-beta3"
|
||||||
gson_version = "2.4"
|
gson_version = "2.4"
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
junit_version = "4.12"
|
junit_version = "4.12"
|
||||||
{{#useRxJava}}
|
{{#useRxJava}}
|
||||||
rx_java_version = "1.0.15"
|
rx_java_version = "1.0.16"
|
||||||
{{/useRxJava}}
|
{{/useRxJava}}
|
||||||
{{^useRxJava}}{{/useRxJava}}
|
{{^useRxJava}}{{/useRxJava}}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.retrofit2:retrofit:$retrofit_version"
|
||||||
compile "com.squareup.retrofit:converter-gson:$retrofit_version"
|
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||||
{{#useRxJava}}
|
{{#useRxJava}}
|
||||||
compile "com.squareup.retrofit:adapter-rxjava:$retrofit_version"
|
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
|
||||||
compile "io.reactivex:rxjava:$rx_java_version"
|
compile "io.reactivex:rxjava:$rx_java_version"
|
||||||
{{/useRxJava}}
|
{{/useRxJava}}
|
||||||
{{^useRxJava}}{{/useRxJava}}
|
{{^useRxJava}}{{/useRxJava}}
|
||||||
|
@ -114,12 +114,12 @@
|
|||||||
<version>${swagger-annotations-version}</version>
|
<version>${swagger-annotations-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>retrofit</artifactId>
|
<artifactId>retrofit</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>converter-gson</artifactId>
|
<artifactId>converter-gson</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -134,7 +134,7 @@
|
|||||||
<version>${oltu-version}</version>
|
<version>${oltu-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
<version>${okhttp-version}</version>
|
<version>${okhttp-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -145,7 +145,7 @@
|
|||||||
<version>${rxjava-version}</version>
|
<version>${rxjava-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>adapter-rxjava</artifactId>
|
<artifactId>adapter-rxjava</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -161,9 +161,9 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||||
{{#useRxJava}}<rxjava-version>1.0.15</rxjava-version>{{/useRxJava}}
|
{{#useRxJava}}<rxjava-version>1.0.16</rxjava-version>{{/useRxJava}}
|
||||||
<okhttp-version>2.5.0</okhttp-version>
|
<okhttp-version>3.0.1</okhttp-version>
|
||||||
<gson-version>2.4</gson-version>
|
<gson-version>2.4</gson-version>
|
||||||
<oltu-version>1.0.0</oltu-version>
|
<oltu-version>1.0.0</oltu-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
group = 'io.swagger'
|
group = 'io.swagger'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
|
|
||||||
@ -20,7 +23,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'com.github.dcendents.android-maven'
|
apply plugin: 'com.github.dcendents.android-maven'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 22
|
compileSdkVersion 22
|
||||||
buildToolsVersion '22.0.0'
|
buildToolsVersion '22.0.0'
|
||||||
@ -32,7 +35,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
sourceCompatibility JavaVersion.VERSION_1_7
|
sourceCompatibility JavaVersion.VERSION_1_7
|
||||||
targetCompatibility JavaVersion.VERSION_1_7
|
targetCompatibility JavaVersion.VERSION_1_7
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rename the aar correctly
|
// Rename the aar correctly
|
||||||
libraryVariants.all { variant ->
|
libraryVariants.all { variant ->
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
@ -44,7 +47,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
afterEvaluate {
|
afterEvaluate {
|
||||||
android.libraryVariants.all { variant ->
|
android.libraryVariants.all { variant ->
|
||||||
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
|
||||||
@ -56,12 +59,12 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
artifacts.add('archives', task);
|
artifacts.add('archives', task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task sourcesJar(type: Jar) {
|
task sourcesJar(type: Jar) {
|
||||||
from android.sourceSets.main.java.srcDirs
|
from android.sourceSets.main.java.srcDirs
|
||||||
classifier = 'sources'
|
classifier = 'sources'
|
||||||
}
|
}
|
||||||
|
|
||||||
artifacts {
|
artifacts {
|
||||||
archives sourcesJar
|
archives sourcesJar
|
||||||
}
|
}
|
||||||
@ -70,16 +73,16 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_7
|
||||||
|
|
||||||
install {
|
install {
|
||||||
repositories.mavenInstaller {
|
repositories.mavenInstaller {
|
||||||
pom.artifactId = 'swagger-petstore-retrofit2'
|
pom.artifactId = 'swagger-petstore-retrofit2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task execute(type:JavaExec) {
|
task execute(type:JavaExec) {
|
||||||
main = System.getProperty('mainClass')
|
main = System.getProperty('mainClass')
|
||||||
classpath = sourceSets.main.runtimeClasspath
|
classpath = sourceSets.main.runtimeClasspath
|
||||||
@ -87,20 +90,25 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
okhttp_version = "2.5.0"
|
okhttp_version = "3.0.1"
|
||||||
oltu_version = "1.0.0"
|
oltu_version = "1.0.0"
|
||||||
retrofit_version = "2.0.0-beta2"
|
retrofit_version = "2.0.0-beta3"
|
||||||
gson_version = "2.4"
|
gson_version = "2.4"
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
junit_version = "4.12"
|
junit_version = "4.12"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.retrofit2:retrofit:$retrofit_version"
|
||||||
|
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||||
|
|
||||||
|
|
||||||
compile "com.google.code.gson:gson:$gson_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 "io.swagger:swagger-annotations:$swagger_annotations_version"
|
||||||
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
|
compile "org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:$oltu_version"
|
||||||
|
|
||||||
testCompile "junit:junit:$junit_version"
|
testCompile "junit:junit:$junit_version"
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,9 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.6</source>
|
<source>
|
||||||
<target>1.6</target>
|
1.7</source>
|
||||||
|
<target>1.7</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -113,12 +114,12 @@
|
|||||||
<version>${swagger-annotations-version}</version>
|
<version>${swagger-annotations-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>retrofit</artifactId>
|
<artifactId>retrofit</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>converter-gson</artifactId>
|
<artifactId>converter-gson</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -133,10 +134,11 @@
|
|||||||
<version>${oltu-version}</version>
|
<version>${oltu-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
<version>${okhttp-version}</version>
|
<version>${okhttp-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- test dependencies -->
|
<!-- test dependencies -->
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -148,8 +150,9 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||||
<okhttp-version>2.5.0</okhttp-version>
|
|
||||||
|
<okhttp-version>3.0.1</okhttp-version>
|
||||||
<gson-version>2.4</gson-version>
|
<gson-version>2.4</gson-version>
|
||||||
<oltu-version>1.0.0</oltu-version>
|
<oltu-version>1.0.0</oltu-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-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.AuthenticationRequestBuilder;
|
||||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||||
|
|
||||||
import retrofit.Converter;
|
import retrofit2.Converter;
|
||||||
import retrofit.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit.GsonConverterFactory;
|
import retrofit2.GsonConverterFactory;
|
||||||
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import com.squareup.okhttp.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
|
||||||
import io.swagger.client.auth.HttpBasicAuth;
|
import io.swagger.client.auth.HttpBasicAuth;
|
||||||
import io.swagger.client.auth.ApiKeyAuth;
|
import io.swagger.client.auth.ApiKeyAuth;
|
||||||
@ -44,10 +46,10 @@ public class ApiClient {
|
|||||||
this();
|
this();
|
||||||
for(String authName : authNames) {
|
for(String authName : authNames) {
|
||||||
Interceptor auth;
|
Interceptor auth;
|
||||||
if (authName == "api_key") {
|
if (authName == "petstore_auth") {
|
||||||
auth = new ApiKeyAuth("header", "api_key");
|
|
||||||
} else if (authName == "petstore_auth") {
|
|
||||||
auth = new OAuth(OAuthFlow.implicit, "http://petstore.swagger.io/api/oauth/dialog", "", "write:pets, read:pets");
|
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 {
|
} else {
|
||||||
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
throw new RuntimeException("auth name \"" + authName + "\" not found in available auth names");
|
||||||
}
|
}
|
||||||
@ -116,6 +118,7 @@ public class ApiClient {
|
|||||||
.Builder()
|
.Builder()
|
||||||
.baseUrl(baseUrl)
|
.baseUrl(baseUrl)
|
||||||
.client(okClient)
|
.client(okClient)
|
||||||
|
|
||||||
.addConverterFactory(GsonCustomConverterFactory.create(gson));
|
.addConverterFactory(GsonCustomConverterFactory.create(gson));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +283,7 @@ public class ApiClient {
|
|||||||
* @param okClient
|
* @param okClient
|
||||||
*/
|
*/
|
||||||
public void configureFromOkclient(OkHttpClient okClient) {
|
public void configureFromOkclient(OkHttpClient okClient) {
|
||||||
OkHttpClient clone = okClient.clone();
|
OkHttpClient clone = okClient.newBuilder().build();
|
||||||
addAuthsToOkClient(clone);
|
addAuthsToOkClient(clone);
|
||||||
adapterBuilder.client(clone);
|
adapterBuilder.client(clone);
|
||||||
}
|
}
|
||||||
@ -326,17 +329,17 @@ class GsonCustomConverterFactory extends Converter.Factory
|
|||||||
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
if(type.equals(String.class))
|
if(type.equals(String.class))
|
||||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||||
else
|
else
|
||||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package io.swagger.client;
|
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 {
|
public class StringUtil {
|
||||||
/**
|
/**
|
||||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
* 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 io.swagger.client.CollectionFormats.*;
|
||||||
|
|
||||||
import retrofit.Call;
|
|
||||||
import retrofit.http.*;
|
import retrofit2.Call;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import io.swagger.client.model.Pet;
|
import io.swagger.client.model.Pet;
|
||||||
import java.io.File;
|
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 io.swagger.client.CollectionFormats.*;
|
||||||
|
|
||||||
import retrofit.Call;
|
|
||||||
import retrofit.http.*;
|
import retrofit2.Call;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import io.swagger.client.model.Order;
|
import io.swagger.client.model.Order;
|
||||||
|
@ -2,9 +2,11 @@ package io.swagger.client.api;
|
|||||||
|
|
||||||
import io.swagger.client.CollectionFormats.*;
|
import io.swagger.client.CollectionFormats.*;
|
||||||
|
|
||||||
import retrofit.Call;
|
|
||||||
import retrofit.http.*;
|
import retrofit2.Call;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import io.swagger.client.model.User;
|
import io.swagger.client.model.User;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class ApiKeyAuth implements Interceptor {
|
public class ApiKeyAuth implements Interceptor {
|
||||||
private final String location;
|
private final String location;
|
||||||
@ -41,18 +41,18 @@ public class ApiKeyAuth implements Interceptor {
|
|||||||
Request request = chain.request();
|
Request request = chain.request();
|
||||||
|
|
||||||
if (location == "query") {
|
if (location == "query") {
|
||||||
String newQuery = request.uri().getQuery();
|
String newQuery = request.url().uri().getQuery();
|
||||||
paramValue = paramName + "=" + apiKey;
|
paramValue = paramName + "=" + apiKey;
|
||||||
if (newQuery == null) {
|
if (newQuery == null) {
|
||||||
newQuery = paramValue;
|
newQuery = paramValue;
|
||||||
} else {
|
} else {
|
||||||
newQuery += "&" + paramValue;
|
newQuery += "&" + paramValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
URI newUri;
|
URI newUri;
|
||||||
try {
|
try {
|
||||||
newUri = new URI(request.uri().getScheme(), request.uri().getAuthority(),
|
newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(),
|
||||||
request.uri().getPath(), newQuery, request.uri().getFragment());
|
request.url().uri().getPath(), newQuery, request.url().uri().getFragment());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package io.swagger.client.auth;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Credentials;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.Credentials;
|
||||||
|
|
||||||
public class HttpBasicAuth implements Interceptor {
|
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.message.types.GrantType;
|
||||||
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Request.Builder;
|
import okhttp3.Request.Builder;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class OAuth implements Interceptor {
|
public class OAuth implements Interceptor {
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ public class OAuth implements Interceptor {
|
|||||||
|
|
||||||
String requestAccessToken = new String(getAccessToken());
|
String requestAccessToken = new String(getAccessToken());
|
||||||
try {
|
try {
|
||||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||||
.setAccessToken(requestAccessToken)
|
.setAccessToken(requestAccessToken)
|
||||||
.buildHeaderMessage();
|
.buildHeaderMessage();
|
||||||
} catch (OAuthSystemException e) {
|
} catch (OAuthSystemException e) {
|
||||||
throw new IOException(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.OAuthProblemException;
|
||||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||||
|
|
||||||
import com.squareup.okhttp.MediaType;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Request.Builder;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
|
|
||||||
public class OAuthOkHttpClient implements HttpClient {
|
public class OAuthOkHttpClient implements HttpClient {
|
||||||
|
@ -15,10 +15,10 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import retrofit.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
import com.squareup.okhttp.MediaType;
|
import okhttp3.MediaType;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@ -141,7 +141,7 @@ public class PetApiTest {
|
|||||||
writer.write("Hello world!");
|
writer.write("Hello world!");
|
||||||
writer.close();
|
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
|
@Test
|
||||||
|
@ -10,7 +10,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import retrofit.Response;
|
import retrofit2.Response;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class StoreApiTest {
|
public class StoreApiTest {
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
apply plugin: 'idea'
|
||||||
|
apply plugin: 'eclipse'
|
||||||
|
|
||||||
group = 'io.swagger'
|
group = 'io.swagger'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
|
|
||||||
@ -71,12 +74,12 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
|
||||||
sourceCompatibility = JavaVersion.VERSION_1_7
|
sourceCompatibility = JavaVersion.VERSION_1_7
|
||||||
targetCompatibility = JavaVersion.VERSION_1_7
|
targetCompatibility = JavaVersion.VERSION_1_7
|
||||||
|
|
||||||
install {
|
install {
|
||||||
repositories.mavenInstaller {
|
repositories.mavenInstaller {
|
||||||
pom.artifactId = 'swagger-petstore-retrofit2-rx'
|
pom.artifactId = 'swagger-petstore-retrofit2-rx'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,22 +90,22 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
okhttp_version = "2.5.0"
|
okhttp_version = "3.0.1"
|
||||||
oltu_version = "1.0.0"
|
oltu_version = "1.0.0"
|
||||||
retrofit_version = "2.0.0-beta2"
|
retrofit_version = "2.0.0-beta3"
|
||||||
gson_version = "2.4"
|
gson_version = "2.4"
|
||||||
swagger_annotations_version = "1.5.0"
|
swagger_annotations_version = "1.5.0"
|
||||||
junit_version = "4.12"
|
junit_version = "4.12"
|
||||||
rx_java_version = "1.0.15"
|
rx_java_version = "1.0.16"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
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.retrofit2:retrofit:$retrofit_version"
|
||||||
compile "com.squareup.retrofit:converter-gson:$retrofit_version"
|
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
|
||||||
compile "com.squareup.retrofit:adapter-rxjava:$retrofit_version"
|
compile "com.squareup.retrofit2:adapter-rxjava:$retrofit_version"
|
||||||
compile "io.reactivex:rxjava:$rx_java_version"
|
compile "io.reactivex:rxjava:$rx_java_version"
|
||||||
|
|
||||||
|
|
||||||
|
@ -100,10 +100,9 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.3.2</version>
|
<version>2.3.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>
|
<source>
|
||||||
1.7
|
1.7</source>
|
||||||
</source>
|
<target>1.7</target>
|
||||||
<target>1.7</target>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -115,12 +114,12 @@
|
|||||||
<version>${swagger-annotations-version}</version>
|
<version>${swagger-annotations-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>retrofit</artifactId>
|
<artifactId>retrofit</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>converter-gson</artifactId>
|
<artifactId>converter-gson</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -135,7 +134,7 @@
|
|||||||
<version>${oltu-version}</version>
|
<version>${oltu-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
<artifactId>okhttp</artifactId>
|
<artifactId>okhttp</artifactId>
|
||||||
<version>${okhttp-version}</version>
|
<version>${okhttp-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -146,7 +145,7 @@
|
|||||||
<version>${rxjava-version}</version>
|
<version>${rxjava-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.retrofit</groupId>
|
<groupId>com.squareup.retrofit2</groupId>
|
||||||
<artifactId>adapter-rxjava</artifactId>
|
<artifactId>adapter-rxjava</artifactId>
|
||||||
<version>${retrofit-version}</version>
|
<version>${retrofit-version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
@ -162,9 +161,9 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
<swagger-annotations-version>1.5.0</swagger-annotations-version>
|
||||||
<retrofit-version>2.0.0-beta2</retrofit-version>
|
<retrofit-version>2.0.0-beta3</retrofit-version>
|
||||||
<rxjava-version>1.0.15</rxjava-version>
|
<rxjava-version>1.0.16</rxjava-version>
|
||||||
<okhttp-version>2.5.0</okhttp-version>
|
<okhttp-version>3.0.1</okhttp-version>
|
||||||
<gson-version>2.4</gson-version>
|
<gson-version>2.4</gson-version>
|
||||||
<oltu-version>1.0.0</oltu-version>
|
<oltu-version>1.0.0</oltu-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-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.AuthenticationRequestBuilder;
|
||||||
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
|
||||||
|
|
||||||
import retrofit.Converter;
|
import retrofit2.Converter;
|
||||||
import retrofit.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
import retrofit.GsonConverterFactory;
|
import retrofit2.GsonConverterFactory;
|
||||||
import retrofit.RxJavaCallAdapterFactory;
|
import retrofit2.RxJavaCallAdapterFactory;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonParseException;
|
import com.google.gson.JsonParseException;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import com.squareup.okhttp.ResponseBody;
|
import okhttp3.ResponseBody;
|
||||||
|
|
||||||
|
|
||||||
import io.swagger.client.auth.HttpBasicAuth;
|
import io.swagger.client.auth.HttpBasicAuth;
|
||||||
@ -283,7 +283,7 @@ public class ApiClient {
|
|||||||
* @param okClient
|
* @param okClient
|
||||||
*/
|
*/
|
||||||
public void configureFromOkclient(OkHttpClient okClient) {
|
public void configureFromOkclient(OkHttpClient okClient) {
|
||||||
OkHttpClient clone = okClient.clone();
|
OkHttpClient clone = okClient.newBuilder().build();
|
||||||
addAuthsToOkClient(clone);
|
addAuthsToOkClient(clone);
|
||||||
adapterBuilder.client(clone);
|
adapterBuilder.client(clone);
|
||||||
}
|
}
|
||||||
@ -329,17 +329,17 @@ class GsonCustomConverterFactory extends Converter.Factory
|
|||||||
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
this.gsonConverterFactory = GsonConverterFactory.create(gson);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
|
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
if(type.equals(String.class))
|
if(type.equals(String.class))
|
||||||
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
return new GsonResponseBodyConverterToString<Object>(gson, type);
|
||||||
else
|
else
|
||||||
return gsonConverterFactory.fromResponseBody(type, annotations);
|
return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Converter<?, RequestBody> toRequestBody(Type type, Annotation[] annotations) {
|
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||||
return gsonConverterFactory.toRequestBody(type, annotations);
|
return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package io.swagger.client;
|
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 {
|
public class StringUtil {
|
||||||
/**
|
/**
|
||||||
* Check if the given array contains the given value (with case-insensitive comparison).
|
* 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 rx.Observable;
|
||||||
|
|
||||||
import retrofit.http.*;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import io.swagger.client.model.Pet;
|
import io.swagger.client.model.Pet;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -4,9 +4,9 @@ import io.swagger.client.CollectionFormats.*;
|
|||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
import retrofit.http.*;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import io.swagger.client.model.Order;
|
import io.swagger.client.model.Order;
|
||||||
|
@ -4,9 +4,9 @@ import io.swagger.client.CollectionFormats.*;
|
|||||||
|
|
||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
|
|
||||||
import retrofit.http.*;
|
import retrofit2.http.*;
|
||||||
|
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import io.swagger.client.model.User;
|
import io.swagger.client.model.User;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -4,9 +4,9 @@ import java.io.IOException;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class ApiKeyAuth implements Interceptor {
|
public class ApiKeyAuth implements Interceptor {
|
||||||
private final String location;
|
private final String location;
|
||||||
@ -41,18 +41,18 @@ public class ApiKeyAuth implements Interceptor {
|
|||||||
Request request = chain.request();
|
Request request = chain.request();
|
||||||
|
|
||||||
if (location == "query") {
|
if (location == "query") {
|
||||||
String newQuery = request.uri().getQuery();
|
String newQuery = request.url().uri().getQuery();
|
||||||
paramValue = paramName + "=" + apiKey;
|
paramValue = paramName + "=" + apiKey;
|
||||||
if (newQuery == null) {
|
if (newQuery == null) {
|
||||||
newQuery = paramValue;
|
newQuery = paramValue;
|
||||||
} else {
|
} else {
|
||||||
newQuery += "&" + paramValue;
|
newQuery += "&" + paramValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
URI newUri;
|
URI newUri;
|
||||||
try {
|
try {
|
||||||
newUri = new URI(request.uri().getScheme(), request.uri().getAuthority(),
|
newUri = new URI(request.url().uri().getScheme(), request.url().uri().getAuthority(),
|
||||||
request.uri().getPath(), newQuery, request.uri().getFragment());
|
request.url().uri().getPath(), newQuery, request.url().uri().getFragment());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,11 @@ package io.swagger.client.auth;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import com.squareup.okhttp.Credentials;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
import okhttp3.Credentials;
|
||||||
|
|
||||||
public class HttpBasicAuth implements Interceptor {
|
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.message.types.GrantType;
|
||||||
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
import org.apache.oltu.oauth2.common.token.BasicOAuthToken;
|
||||||
|
|
||||||
import com.squareup.okhttp.Interceptor;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Request.Builder;
|
import okhttp3.Request.Builder;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class OAuth implements Interceptor {
|
public class OAuth implements Interceptor {
|
||||||
|
|
||||||
@ -90,9 +90,9 @@ public class OAuth implements Interceptor {
|
|||||||
|
|
||||||
String requestAccessToken = new String(getAccessToken());
|
String requestAccessToken = new String(getAccessToken());
|
||||||
try {
|
try {
|
||||||
oAuthRequest = new OAuthBearerClientRequest(request.urlString())
|
oAuthRequest = new OAuthBearerClientRequest(request.url().toString())
|
||||||
.setAccessToken(requestAccessToken)
|
.setAccessToken(requestAccessToken)
|
||||||
.buildHeaderMessage();
|
.buildHeaderMessage();
|
||||||
} catch (OAuthSystemException e) {
|
} catch (OAuthSystemException e) {
|
||||||
throw new IOException(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.OAuthProblemException;
|
||||||
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
|
||||||
|
|
||||||
import com.squareup.okhttp.MediaType;
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import okhttp3.Interceptor;
|
||||||
import com.squareup.okhttp.Request;
|
import okhttp3.OkHttpClient;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.Request;
|
||||||
import com.squareup.okhttp.Response;
|
import okhttp3.Request.Builder;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import okhttp3.MediaType;
|
||||||
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
|
|
||||||
public class OAuthOkHttpClient implements HttpClient {
|
public class OAuthOkHttpClient implements HttpClient {
|
||||||
|
@ -13,8 +13,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import com.squareup.okhttp.MediaType;
|
import okhttp3.MediaType;
|
||||||
import com.squareup.okhttp.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.junit.*;
|
import org.junit.*;
|
||||||
|
|
||||||
import retrofit.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user