diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache index 6cd8aa399f1..11903b535f5 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/ApiClient.mustache @@ -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 fromResponseBody(Type type, Annotation[] annotations) { - if(type.equals(String.class)) - return new GsonResponseBodyConverterToString(gson, type); - else - return gsonConverterFactory.fromResponseBody(type, annotations); - } + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + if(type.equals(String.class)) + return new GsonResponseBodyConverterToString(gson, type); + else + return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit); + } - @Override - public Converter toRequestBody(Type type, Annotation[] annotations) { - return gsonConverterFactory.toRequestBody(type, annotations); - } + @Override + public Converter requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + } } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache index ff90557a3fa..5fa920754e0 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/api.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/ApiKeyAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/ApiKeyAuth.mustache index fec45262e93..92c0df0ddea 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/ApiKeyAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/ApiKeyAuth.mustache @@ -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); } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/HttpBasicAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/HttpBasicAuth.mustache index 394592f64d9..d4588426662 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/HttpBasicAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/HttpBasicAuth.mustache @@ -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 { diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuth.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuth.mustache index 68ee918601e..0997418a210 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuth.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuth.mustache @@ -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); } diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuthOkHttpClient.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuthOkHttpClient.mustache index ea195f7df04..423fa1ba0e5 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuthOkHttpClient.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/auth/OAuthOkHttpClient.mustache @@ -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 { diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache index adf19b2139a..d7dd471b18c 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/build.gradle.mustache @@ -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}} diff --git a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache index ef322cccb09..40e537161c0 100644 --- a/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache +++ b/modules/swagger-codegen/src/main/resources/Java/libraries/retrofit2/pom.mustache @@ -114,12 +114,12 @@ ${swagger-annotations-version} - com.squareup.retrofit + com.squareup.retrofit2 retrofit ${retrofit-version} - com.squareup.retrofit + com.squareup.retrofit2 converter-gson ${retrofit-version} @@ -134,7 +134,7 @@ ${oltu-version} - com.squareup.okhttp + com.squareup.okhttp3 okhttp ${okhttp-version} @@ -145,7 +145,7 @@ ${rxjava-version} - com.squareup.retrofit + com.squareup.retrofit2 adapter-rxjava ${retrofit-version} @@ -161,9 +161,9 @@ 1.5.0 - 2.0.0-beta2 - {{#useRxJava}}1.0.15{{/useRxJava}} - 2.5.0 + 2.0.0-beta3 + {{#useRxJava}}1.0.16{{/useRxJava}} + 3.0.1 2.4 1.0.0 1.0.0 diff --git a/samples/client/petstore/java/retrofit2/build.gradle b/samples/client/petstore/java/retrofit2/build.gradle index 29e1737f3b3..8eee8f18489 100644 --- a/samples/client/petstore/java/retrofit2/build.gradle +++ b/samples/client/petstore/java/retrofit2/build.gradle @@ -1,3 +1,6 @@ +apply plugin: 'idea' +apply plugin: 'eclipse' + group = 'io.swagger' version = '1.0.0' @@ -20,7 +23,7 @@ if(hasProperty('target') && target == 'android') { apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' - + android { compileSdkVersion 22 buildToolsVersion '22.0.0' @@ -32,7 +35,7 @@ if(hasProperty('target') && target == 'android') { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } - + // Rename the aar correctly libraryVariants.all { variant -> variant.outputs.each { output -> @@ -44,7 +47,7 @@ if(hasProperty('target') && target == 'android') { } } } - + afterEvaluate { android.libraryVariants.all { variant -> def task = project.tasks.create "jar${variant.name.capitalize()}", Jar @@ -56,12 +59,12 @@ if(hasProperty('target') && target == 'android') { artifacts.add('archives', task); } } - + task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } - + artifacts { archives sourcesJar } @@ -70,16 +73,16 @@ 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 { pom.artifactId = 'swagger-petstore-retrofit2' } } - + task execute(type:JavaExec) { main = System.getProperty('mainClass') classpath = sourceSets.main.runtimeClasspath @@ -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" } diff --git a/samples/client/petstore/java/retrofit2/pom.xml b/samples/client/petstore/java/retrofit2/pom.xml index 109cbc0d95c..39f3857db33 100644 --- a/samples/client/petstore/java/retrofit2/pom.xml +++ b/samples/client/petstore/java/retrofit2/pom.xml @@ -100,8 +100,9 @@ maven-compiler-plugin 2.3.2 - 1.6 - 1.6 + + 1.7 + 1.7 @@ -113,12 +114,12 @@ ${swagger-annotations-version} - com.squareup.retrofit + com.squareup.retrofit2 retrofit ${retrofit-version} - com.squareup.retrofit + com.squareup.retrofit2 converter-gson ${retrofit-version} @@ -133,10 +134,11 @@ ${oltu-version} - com.squareup.okhttp + com.squareup.okhttp3 okhttp ${okhttp-version} + @@ -148,8 +150,9 @@ 1.5.0 - 2.0.0-beta2 - 2.5.0 + 2.0.0-beta3 + + 3.0.1 2.4 1.0.0 1.0.0 diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java index 75e641c689c..dd3bde9372d 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/ApiClient.java @@ -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); } @@ -326,17 +329,17 @@ class GsonCustomConverterFactory extends Converter.Factory this.gsonConverterFactory = GsonConverterFactory.create(gson); } - @Override - public Converter fromResponseBody(Type type, Annotation[] annotations) { - if(type.equals(String.class)) - return new GsonResponseBodyConverterToString(gson, type); - else - return gsonConverterFactory.fromResponseBody(type, annotations); - } + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + if(type.equals(String.class)) + return new GsonResponseBodyConverterToString(gson, type); + else + return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit); + } - @Override - public Converter toRequestBody(Type type, Annotation[] annotations) { - return gsonConverterFactory.toRequestBody(type, annotations); - } + @Override + public Converter requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + } } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java index c3d32254540..f77418464bf 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/StringUtil.java @@ -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). diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/PetApi.java index a55cf74da76..9f89e8e686e 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/PetApi.java @@ -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 + */ + + @GET("pet/{petId}?testing_byte_array=true") + Call 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 + */ + + @POST("pet?testing_byte_array=true") + Call addPetUsingByteArray( + @Body byte[] body + ); + + } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/StoreApi.java index 2fca1e02e39..06b463aaf3c 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/StoreApi.java @@ -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; diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/UserApi.java index 928bd623020..7c1e7d44a78 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/api/UserApi.java @@ -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.*; diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 59d01238796..f210c2110b5 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -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); } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index cb7c617767b..c7b67e2d781 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -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 { diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuth.java index 80614f0f56a..d9eed067a88 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuth.java @@ -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); } diff --git a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java index c872901ba24..c9b6e124d51 100644 --- a/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java +++ b/samples/client/petstore/java/retrofit2/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java @@ -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 { diff --git a/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/PetApiTest.java index ec5116e45f6..3905fb962e3 100644 --- a/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -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 diff --git a/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/StoreApiTest.java b/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/StoreApiTest.java index 71f77ec9b41..7c15e76ffa5 100644 --- a/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/StoreApiTest.java +++ b/samples/client/petstore/java/retrofit2/src/test/java/io/swagger/petstore/test/StoreApiTest.java @@ -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 { diff --git a/samples/client/petstore/java/retrofit2rx/build.gradle b/samples/client/petstore/java/retrofit2rx/build.gradle index 08c81cd21ea..6b72ef69557 100644 --- a/samples/client/petstore/java/retrofit2rx/build.gradle +++ b/samples/client/petstore/java/retrofit2rx/build.gradle @@ -1,3 +1,6 @@ +apply plugin: 'idea' +apply plugin: 'eclipse' + group = 'io.swagger' version = '1.0.0' @@ -71,12 +74,12 @@ 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 { - pom.artifactId = 'swagger-petstore-retrofit2-rx' + pom.artifactId = 'swagger-petstore-retrofit2-rx' } } @@ -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" diff --git a/samples/client/petstore/java/retrofit2rx/pom.xml b/samples/client/petstore/java/retrofit2rx/pom.xml index ab018917b14..2881967993d 100644 --- a/samples/client/petstore/java/retrofit2rx/pom.xml +++ b/samples/client/petstore/java/retrofit2rx/pom.xml @@ -100,10 +100,9 @@ maven-compiler-plugin 2.3.2 - - 1.7 - - 1.7 + + 1.7 + 1.7 @@ -115,12 +114,12 @@ ${swagger-annotations-version} - com.squareup.retrofit + com.squareup.retrofit2 retrofit ${retrofit-version} - com.squareup.retrofit + com.squareup.retrofit2 converter-gson ${retrofit-version} @@ -135,7 +134,7 @@ ${oltu-version} - com.squareup.okhttp + com.squareup.okhttp3 okhttp ${okhttp-version} @@ -146,7 +145,7 @@ ${rxjava-version} - com.squareup.retrofit + com.squareup.retrofit2 adapter-rxjava ${retrofit-version} @@ -162,9 +161,9 @@ 1.5.0 - 2.0.0-beta2 - 1.0.15 - 2.5.0 + 2.0.0-beta3 + 1.0.16 + 3.0.1 2.4 1.0.0 1.0.0 diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java index 869681a2ce5..5b05ce22e66 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/ApiClient.java @@ -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); } @@ -329,17 +329,17 @@ class GsonCustomConverterFactory extends Converter.Factory this.gsonConverterFactory = GsonConverterFactory.create(gson); } - @Override - public Converter fromResponseBody(Type type, Annotation[] annotations) { - if(type.equals(String.class)) - return new GsonResponseBodyConverterToString(gson, type); - else - return gsonConverterFactory.fromResponseBody(type, annotations); - } + @Override + public Converter responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + if(type.equals(String.class)) + return new GsonResponseBodyConverterToString(gson, type); + else + return gsonConverterFactory.responseBodyConverter(type, annotations, retrofit); + } - @Override - public Converter toRequestBody(Type type, Annotation[] annotations) { - return gsonConverterFactory.toRequestBody(type, annotations); - } + @Override + public Converter requestBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) { + return gsonConverterFactory.requestBodyConverter(type, annotations, retrofit); + } } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java index 4a8e24d7cb7..9f06b50e8b9 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/StringUtil.java @@ -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). diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/PetApi.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/PetApi.java index 7caa426e18d..96eed68c86e 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/PetApi.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/PetApi.java @@ -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; diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/StoreApi.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/StoreApi.java index 20e4dbb57fa..0fbca2d44da 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/StoreApi.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/StoreApi.java @@ -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; diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/UserApi.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/UserApi.java index ec6fd019252..e44262f7da2 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/UserApi.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/api/UserApi.java @@ -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.*; diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/ApiKeyAuth.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/ApiKeyAuth.java index 59d01238796..f210c2110b5 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/ApiKeyAuth.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/ApiKeyAuth.java @@ -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); } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/HttpBasicAuth.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/HttpBasicAuth.java index cb7c617767b..c7b67e2d781 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/HttpBasicAuth.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/HttpBasicAuth.java @@ -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 { diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuth.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuth.java index 80614f0f56a..d9eed067a88 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuth.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuth.java @@ -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); } diff --git a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java index c872901ba24..c9b6e124d51 100644 --- a/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java +++ b/samples/client/petstore/java/retrofit2rx/src/main/java/io/swagger/client/auth/OAuthOkHttpClient.java @@ -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 { diff --git a/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/PetApiTest.java b/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/PetApiTest.java index d8450642f6f..a433321a0f9 100644 --- a/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/PetApiTest.java +++ b/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/PetApiTest.java @@ -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.*; diff --git a/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/StoreApiTest.java b/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/StoreApiTest.java index d9e2c641398..6d7ee2a77aa 100644 --- a/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/StoreApiTest.java +++ b/samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/petstore/test/StoreApiTest.java @@ -8,7 +8,7 @@ import java.util.Map; import org.junit.*; -import retrofit.Response; +import retrofit2.Response; import static org.junit.Assert.*;