Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/utils/test_file_list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/ClientTest.java"
sha256: 325fdd5d7e2c97790c0fb44f712ab7b2ba022d7e1a5b0056f47b07f342682b6d
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/JSONTest.java"
sha256: e673d9928c8eb848262d0116fe0d28db832e128671a810a7c966d06d90cb9b63
sha256: 67941355a0a27ed9ff9318b1caa103e78b81b9aff61b594b18be5cd2bb9f6591
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java"
sha256: 8b1b8f2a2ad00ccb090873a94a5f73e328b98317d2ec715f53bd7a1accb2a023
- filename: "samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/model/PetTest.java"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1166,17 +1166,8 @@ public class ApiClient {
return (T) downloadFileFromResponse(response);
}

String respBody;
try {
if (response.body() != null)
respBody = response.body().string();
else
respBody = null;
} catch (IOException e) {
throw new ApiException(e);
}

if (respBody == null || "".equals(respBody)) {
ResponseBody respBody = response.body();
if (respBody == null) {
return null;
}

Expand All @@ -1185,17 +1176,25 @@ public class ApiClient {
// ensuring a default content type
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
} else {
throw new ApiException(
try {
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody.byteStream(), returnType);
} else if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {
return null;
}
// Expecting string, return the raw response body.
return (T) respBodyString;
} else {
throw new ApiException(
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);
response.body().string());
}
} catch (IOException e) {
throw new ApiException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import org.joda.time.format.ISODateTimeFormat;
import okio.ByteString;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
Expand Down Expand Up @@ -198,6 +201,28 @@ public class JSON {
}
}

/**
* Deserialize the given JSON InputStream to a Java object.
*
* @param <T> Type
* @param inputStream The JSON InputStream
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
if (isLenientOnJson) {
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(reader, returnType);
}
}
}

/**
* Gson TypeAdapter for Byte Array type
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ defmodule {{moduleName}}.Connection do
of the function call, will be set as a bearer token in the
`authorization` header.
{{/hasOAuthMethods}}
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
- `options`: a keyword list of {{moduleName}}.Connection.options.

### Returns

Expand Down Expand Up @@ -133,7 +133,7 @@ defmodule {{moduleName}}.Connection do
that returns a bearer token.
- `scopes_or_password`: a list of Strings represenging OAuth2 scopes, or
a single string that is the password for the username provided.
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
- `options`: a keyword list of {{moduleName}}.Connection.options.

### Returns

Expand All @@ -155,7 +155,7 @@ defmodule {{moduleName}}.Connection do
of the function call, will be set as a bearer token in the
`authorization` header.
- `scopes`: a list of Strings represenging OAuth2 scopes.
- `options`: a keyword list of OpenAPIPetstore.Connection.options.
- `options`: a keyword list of {{moduleName}}.Connection.options.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a rebase failed and some other changes not authored by you are also included.

given that only a few elixir related changes (already merged into master) are included, we will accept these this time.


### Returns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1006,17 +1006,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
return (T) downloadFileFromResponse(response);
}

String respBody;
try {
if (response.body() != null)
respBody = response.body().string();
else
respBody = null;
} catch (IOException e) {
throw new ApiException(e);
}

if (respBody == null || "".equals(respBody)) {
ResponseBody respBody = response.body();
if (respBody == null) {
return null;
}

Expand All @@ -1025,17 +1016,25 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
// ensuring a default content type
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
} else {
throw new ApiException(
try {
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody.byteStream(), returnType);
} else if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {
return null;
}
// Expecting string, return the raw response body.
return (T) respBodyString;
} else {
throw new ApiException(
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);
response.body().string());
}
} catch (IOException e) {
throw new ApiException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import okio.ByteString;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
Expand Down Expand Up @@ -164,6 +167,28 @@ public static <T> T deserialize(String body, Type returnType) {
}
}

/**
* Deserialize the given JSON InputStream to a Java object.
*
* @param <T> Type
* @param inputStream The JSON InputStream
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
if (isLenientOnJson) {
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(reader, returnType);
}
}
}

/**
* Gson TypeAdapter for Byte Array type
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -936,17 +936,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
return (T) downloadFileFromResponse(response);
}

String respBody;
try {
if (response.body() != null)
respBody = response.body().string();
else
respBody = null;
} catch (IOException e) {
throw new ApiException(e);
}

if (respBody == null || "".equals(respBody)) {
ResponseBody respBody = response.body();
if (respBody == null) {
return null;
}

Expand All @@ -955,17 +946,25 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
// ensuring a default content type
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
} else {
throw new ApiException(
try {
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody.byteStream(), returnType);
} else if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {
return null;
}
// Expecting string, return the raw response body.
return (T) respBodyString;
} else {
throw new ApiException(
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);
response.body().string());
}
} catch (IOException e) {
throw new ApiException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
import okio.ByteString;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
Expand Down Expand Up @@ -168,6 +171,28 @@ public static <T> T deserialize(String body, Type returnType) {
}
}

/**
* Deserialize the given JSON InputStream to a Java object.
*
* @param <T> Type
* @param inputStream The JSON InputStream
* @param returnType The type to deserialize into
* @return The deserialized Java object
*/
@SuppressWarnings("unchecked")
public static <T> T deserialize(InputStream inputStream, Type returnType) throws IOException {
try (InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
if (isLenientOnJson) {
// see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
JsonReader jsonReader = new JsonReader(reader);
jsonReader.setLenient(true);
return gson.fromJson(jsonReader, returnType);
} else {
return gson.fromJson(reader, returnType);
}
}
}

/**
* Gson TypeAdapter for Byte Array type
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -910,17 +910,8 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
return (T) downloadFileFromResponse(response);
}

String respBody;
try {
if (response.body() != null)
respBody = response.body().string();
else
respBody = null;
} catch (IOException e) {
throw new ApiException(e);
}

if (respBody == null || "".equals(respBody)) {
ResponseBody respBody = response.body();
if (respBody == null) {
return null;
}

Expand All @@ -929,17 +920,25 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
// ensuring a default content type
contentType = "application/json";
}
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody, returnType);
} else if (returnType.equals(String.class)) {
// Expecting string, return the raw response body.
return (T) respBody;
} else {
throw new ApiException(
try {
if (isJsonMime(contentType)) {
return JSON.deserialize(respBody.byteStream(), returnType);
} else if (returnType.equals(String.class)) {
String respBodyString = respBody.string();
if (respBodyString.isEmpty()) {
return null;
}
// Expecting string, return the raw response body.
return (T) respBodyString;
} else {
throw new ApiException(
"Content type \"" + contentType + "\" is not supported for type: " + returnType,
response.code(),
response.headers().toMultimap(),
respBody);
response.body().string());
}
} catch (IOException e) {
throw new ApiException(e);
}
}

Expand Down
Loading
Loading