Skip to content

Commit

Permalink
swagger-api#3904 add samples for retrofit2
Browse files Browse the repository at this point in the history
  • Loading branch information
konopski committed Sep 27, 2017
1 parent aab8e82 commit 212ae6c
Show file tree
Hide file tree
Showing 38 changed files with 63 additions and 32 deletions.
2 changes: 1 addition & 1 deletion samples/client/petstore/java/retrofit2/docs/StoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This endpoint does not need any parameter.

### Return type

**Map<String, Integer>**
[**Map<String, Integer>**](Map.md)

### Authorization

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.gson.Gson;
import com.google.gson.JsonParseException;
import com.google.gson.JsonElement;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
Expand All @@ -25,6 +26,7 @@
import java.text.DateFormat;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.HashMap;

public class ApiClient {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
import com.google.gson.internal.bind.util.ISO8601Utils;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.gson.JsonElement;
import io.gsonfire.GsonFireBuilder;
import io.gsonfire.TypeSelector;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.format.DateTimeFormatter;

import io.swagger.client.model.*;

import java.io.IOException;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Date;
import java.util.Map;
import java.util.HashMap;

public class JSON {
private Gson gson;
Expand All @@ -39,8 +46,25 @@ public class JSON {
private OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new OffsetDateTimeTypeAdapter();
private LocalDateTypeAdapter localDateTypeAdapter = new LocalDateTypeAdapter();

public static GsonBuilder createGson() {
GsonFireBuilder fireBuilder = new GsonFireBuilder()
.registerTypeSelector(Animal.class, new TypeSelector() {
@Override
public Class getClassForElement(JsonElement readElement) {
Map classByDiscriminatorValue = new HashMap();
classByDiscriminatorValue.put("Cat".toUpperCase(), Cat.class);
classByDiscriminatorValue.put("Dog".toUpperCase(), Dog.class);
String discriminatorField = "className";
String discriminatorValue = readElement.getAsJsonObject().get(discriminatorField).getAsString();
return (Class) classByDiscriminatorValue.get(discriminatorValue.toUpperCase());
}
})
;
return fireBuilder.createGsonBuilder();
}

public JSON() {
gson = new GsonBuilder()
gson = createGson()
.registerTypeAdapter(Date.class, dateTypeAdapter)
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.http.*;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import java.math.BigDecimal;
import io.swagger.client.model.Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.http.*;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import io.swagger.client.model.Client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.http.*;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import java.io.File;
import io.swagger.client.model.ModelApiResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.http.*;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import io.swagger.client.model.Order;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import retrofit2.http.*;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;

import io.swagger.client.model.User;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ private String toIndentedString(java.lang.Object o) {
}
return o.toString().replace("\n", "\n ");
}

}

0 comments on commit 212ae6c

Please sign in to comment.