forked from loafle/openapi-generator-original
Some code cleanings of problems reported by SonarQube. (#4324)
* Some code cleanings of problems reported by SonarQube. * Updated changes to the petshop sample.
This commit is contained in:
parent
73bf589ad0
commit
c3571b28a5
@ -353,7 +353,7 @@ public class ApiClient {
|
|||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection<?>)param) {
|
for(Object o : (Collection<?>)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(',');
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
@ -372,7 +372,7 @@ public class ApiClient {
|
|||||||
// preconditions
|
// preconditions
|
||||||
if (name == null || name.isEmpty() || value == null) return params;
|
if (name == null || name.isEmpty() || value == null) return params;
|
||||||
|
|
||||||
Collection<?> valueCollection = null;
|
Collection<?> valueCollection;
|
||||||
if (value instanceof Collection<?>) {
|
if (value instanceof Collection<?>) {
|
||||||
valueCollection = (Collection<?>) value;
|
valueCollection = (Collection<?>) value;
|
||||||
} else {
|
} else {
|
||||||
@ -385,10 +385,10 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the collection format
|
// get the collection format
|
||||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||||
|
|
||||||
// create the params based on the collection format
|
// create the params based on the collection format
|
||||||
if (collectionFormat.equals("multi")) {
|
if ("multi".equals(format)) {
|
||||||
for (Object item : valueCollection) {
|
for (Object item : valueCollection) {
|
||||||
params.add(new Pair(name, parameterToString(item)));
|
params.add(new Pair(name, parameterToString(item)));
|
||||||
}
|
}
|
||||||
@ -398,13 +398,13 @@ public class ApiClient {
|
|||||||
|
|
||||||
String delimiter = ",";
|
String delimiter = ",";
|
||||||
|
|
||||||
if (collectionFormat.equals("csv")) {
|
if ("csv".equals(format)) {
|
||||||
delimiter = ",";
|
delimiter = ",";
|
||||||
} else if (collectionFormat.equals("ssv")) {
|
} else if ("ssv".equals(format)) {
|
||||||
delimiter = " ";
|
delimiter = " ";
|
||||||
} else if (collectionFormat.equals("tsv")) {
|
} else if ("tsv".equals(format)) {
|
||||||
delimiter = "\t";
|
delimiter = "\t";
|
||||||
} else if (collectionFormat.equals("pipes")) {
|
} else if ("pipes".equals(format)) {
|
||||||
delimiter = "|";
|
delimiter = "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +329,7 @@ public class ApiClient {
|
|||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection)param) {
|
for(Object o : (Collection)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(',');
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
@ -348,7 +348,7 @@ public class ApiClient {
|
|||||||
// preconditions
|
// preconditions
|
||||||
if (name == null || name.isEmpty() || value == null) return params;
|
if (name == null || name.isEmpty() || value == null) return params;
|
||||||
|
|
||||||
Collection valueCollection = null;
|
Collection valueCollection;
|
||||||
if (value instanceof Collection) {
|
if (value instanceof Collection) {
|
||||||
valueCollection = (Collection) value;
|
valueCollection = (Collection) value;
|
||||||
} else {
|
} else {
|
||||||
@ -361,10 +361,10 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the collection format
|
// get the collection format
|
||||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||||
|
|
||||||
// create the params based on the collection format
|
// create the params based on the collection format
|
||||||
if (collectionFormat.equals("multi")) {
|
if ("multi".equals(format)) {
|
||||||
for (Object item : valueCollection) {
|
for (Object item : valueCollection) {
|
||||||
params.add(new Pair(name, parameterToString(item)));
|
params.add(new Pair(name, parameterToString(item)));
|
||||||
}
|
}
|
||||||
@ -374,13 +374,13 @@ public class ApiClient {
|
|||||||
|
|
||||||
String delimiter = ",";
|
String delimiter = ",";
|
||||||
|
|
||||||
if (collectionFormat.equals("csv")) {
|
if ("csv".equals(format)) {
|
||||||
delimiter = ",";
|
delimiter = ",";
|
||||||
} else if (collectionFormat.equals("ssv")) {
|
} else if ("ssv".equals(format)) {
|
||||||
delimiter = " ";
|
delimiter = " ";
|
||||||
} else if (collectionFormat.equals("tsv")) {
|
} else if ("tsv".equals(format)) {
|
||||||
delimiter = "\t";
|
delimiter = "\t";
|
||||||
} else if (collectionFormat.equals("pipes")) {
|
} else if ("pipes".equals(format)) {
|
||||||
delimiter = "|";
|
delimiter = "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -464,7 +464,7 @@ public class ApiClient {
|
|||||||
* Content-Type (only JSON is supported for now).
|
* Content-Type (only JSON is supported for now).
|
||||||
*/
|
*/
|
||||||
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
||||||
Entity<?> entity = null;
|
Entity<?> entity;
|
||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
@ -495,6 +495,7 @@ public class ApiClient {
|
|||||||
/**
|
/**
|
||||||
* Deserialize response body to Java object according to the Content-Type.
|
* Deserialize response body to Java object according to the Content-Type.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
||||||
if (response == null || returnType == null) {
|
if (response == null || returnType == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -503,9 +504,8 @@ public class ApiClient {
|
|||||||
if ("byte[]".equals(returnType.toString())) {
|
if ("byte[]".equals(returnType.toString())) {
|
||||||
// Handle binary response (byte array).
|
// Handle binary response (byte array).
|
||||||
return (T) response.readEntity(byte[].class);
|
return (T) response.readEntity(byte[].class);
|
||||||
} else if (returnType.equals(File.class)) {
|
} else if (returnType.getRawType() == File.class) {
|
||||||
// Handle file downloading.
|
// Handle file downloading.
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
T file = (T) downloadFileFromResponse(response);
|
T file = (T) downloadFileFromResponse(response);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -551,13 +551,13 @@ public class ApiClient {
|
|||||||
filename = matcher.group(1);
|
filename = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = null;
|
String prefix;
|
||||||
String suffix = null;
|
String suffix = null;
|
||||||
if (filename == null) {
|
if (filename == null) {
|
||||||
prefix = "download-";
|
prefix = "download-";
|
||||||
suffix = "";
|
suffix = "";
|
||||||
} else {
|
} else {
|
||||||
int pos = filename.lastIndexOf(".");
|
int pos = filename.lastIndexOf('.');
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
prefix = filename + "-";
|
prefix = filename + "-";
|
||||||
} else {
|
} else {
|
||||||
@ -607,16 +607,17 @@ public class ApiClient {
|
|||||||
|
|
||||||
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
||||||
|
|
||||||
for (String key : headerParams.keySet()) {
|
for (Entry<String, String> entry : headerParams.entrySet()) {
|
||||||
String value = headerParams.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(entry.getKey(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key : defaultHeaderMap.keySet()) {
|
for (Entry<String, String> entry : defaultHeaderMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
if (!headerParams.containsKey(key)) {
|
if (!headerParams.containsKey(key)) {
|
||||||
String value = defaultHeaderMap.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(key, value);
|
||||||
}
|
}
|
||||||
@ -625,7 +626,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
Entity<?> entity = serialize(body, formParams, contentType);
|
Entity<?> entity = serialize(body, formParams, contentType);
|
||||||
|
|
||||||
Response response = null;
|
Response response;
|
||||||
|
|
||||||
if ("GET".equals(method)) {
|
if ("GET".equals(method)) {
|
||||||
response = invocationBuilder.get();
|
response = invocationBuilder.get();
|
||||||
@ -646,7 +647,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
||||||
return null;
|
return null;
|
||||||
} else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
|
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
|
||||||
if (returnType == null)
|
if (returnType == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Hello world!
|
|
@ -354,7 +354,7 @@ public class ApiClient {
|
|||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection<?>)param) {
|
for(Object o : (Collection<?>)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(',');
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
@ -373,7 +373,7 @@ public class ApiClient {
|
|||||||
// preconditions
|
// preconditions
|
||||||
if (name == null || name.isEmpty() || value == null) return params;
|
if (name == null || name.isEmpty() || value == null) return params;
|
||||||
|
|
||||||
Collection<?> valueCollection = null;
|
Collection<?> valueCollection;
|
||||||
if (value instanceof Collection<?>) {
|
if (value instanceof Collection<?>) {
|
||||||
valueCollection = (Collection<?>) value;
|
valueCollection = (Collection<?>) value;
|
||||||
} else {
|
} else {
|
||||||
@ -386,10 +386,10 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the collection format
|
// get the collection format
|
||||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||||
|
|
||||||
// create the params based on the collection format
|
// create the params based on the collection format
|
||||||
if (collectionFormat.equals("multi")) {
|
if ("multi".equals(format)) {
|
||||||
for (Object item : valueCollection) {
|
for (Object item : valueCollection) {
|
||||||
params.add(new Pair(name, parameterToString(item)));
|
params.add(new Pair(name, parameterToString(item)));
|
||||||
}
|
}
|
||||||
@ -399,13 +399,13 @@ public class ApiClient {
|
|||||||
|
|
||||||
String delimiter = ",";
|
String delimiter = ",";
|
||||||
|
|
||||||
if (collectionFormat.equals("csv")) {
|
if ("csv".equals(format)) {
|
||||||
delimiter = ",";
|
delimiter = ",";
|
||||||
} else if (collectionFormat.equals("ssv")) {
|
} else if ("ssv".equals(format)) {
|
||||||
delimiter = " ";
|
delimiter = " ";
|
||||||
} else if (collectionFormat.equals("tsv")) {
|
} else if ("tsv".equals(format)) {
|
||||||
delimiter = "\t";
|
delimiter = "\t";
|
||||||
} else if (collectionFormat.equals("pipes")) {
|
} else if ("pipes".equals(format)) {
|
||||||
delimiter = "|";
|
delimiter = "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ public class ApiClient {
|
|||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection)param) {
|
for(Object o : (Collection)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(',');
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ public class ApiClient {
|
|||||||
// preconditions
|
// preconditions
|
||||||
if (name == null || name.isEmpty() || value == null) return params;
|
if (name == null || name.isEmpty() || value == null) return params;
|
||||||
|
|
||||||
Collection valueCollection = null;
|
Collection valueCollection;
|
||||||
if (value instanceof Collection) {
|
if (value instanceof Collection) {
|
||||||
valueCollection = (Collection) value;
|
valueCollection = (Collection) value;
|
||||||
} else {
|
} else {
|
||||||
@ -356,10 +356,10 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the collection format
|
// get the collection format
|
||||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||||
|
|
||||||
// create the params based on the collection format
|
// create the params based on the collection format
|
||||||
if (collectionFormat.equals("multi")) {
|
if ("multi".equals(format)) {
|
||||||
for (Object item : valueCollection) {
|
for (Object item : valueCollection) {
|
||||||
params.add(new Pair(name, parameterToString(item)));
|
params.add(new Pair(name, parameterToString(item)));
|
||||||
}
|
}
|
||||||
@ -369,13 +369,13 @@ public class ApiClient {
|
|||||||
|
|
||||||
String delimiter = ",";
|
String delimiter = ",";
|
||||||
|
|
||||||
if (collectionFormat.equals("csv")) {
|
if ("csv".equals(format)) {
|
||||||
delimiter = ",";
|
delimiter = ",";
|
||||||
} else if (collectionFormat.equals("ssv")) {
|
} else if ("ssv".equals(format)) {
|
||||||
delimiter = " ";
|
delimiter = " ";
|
||||||
} else if (collectionFormat.equals("tsv")) {
|
} else if ("tsv".equals(format)) {
|
||||||
delimiter = "\t";
|
delimiter = "\t";
|
||||||
} else if (collectionFormat.equals("pipes")) {
|
} else if ("pipes".equals(format)) {
|
||||||
delimiter = "|";
|
delimiter = "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +459,7 @@ public class ApiClient {
|
|||||||
* Content-Type (only JSON is supported for now).
|
* Content-Type (only JSON is supported for now).
|
||||||
*/
|
*/
|
||||||
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
||||||
Entity<?> entity = null;
|
Entity<?> entity;
|
||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
@ -490,6 +490,7 @@ public class ApiClient {
|
|||||||
/**
|
/**
|
||||||
* Deserialize response body to Java object according to the Content-Type.
|
* Deserialize response body to Java object according to the Content-Type.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
||||||
if (response == null || returnType == null) {
|
if (response == null || returnType == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -498,9 +499,8 @@ public class ApiClient {
|
|||||||
if ("byte[]".equals(returnType.toString())) {
|
if ("byte[]".equals(returnType.toString())) {
|
||||||
// Handle binary response (byte array).
|
// Handle binary response (byte array).
|
||||||
return (T) response.readEntity(byte[].class);
|
return (T) response.readEntity(byte[].class);
|
||||||
} else if (returnType.equals(File.class)) {
|
} else if (returnType.getRawType() == File.class) {
|
||||||
// Handle file downloading.
|
// Handle file downloading.
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
T file = (T) downloadFileFromResponse(response);
|
T file = (T) downloadFileFromResponse(response);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -540,13 +540,13 @@ public class ApiClient {
|
|||||||
filename = matcher.group(1);
|
filename = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = null;
|
String prefix;
|
||||||
String suffix = null;
|
String suffix = null;
|
||||||
if (filename == null) {
|
if (filename == null) {
|
||||||
prefix = "download-";
|
prefix = "download-";
|
||||||
suffix = "";
|
suffix = "";
|
||||||
} else {
|
} else {
|
||||||
int pos = filename.lastIndexOf(".");
|
int pos = filename.lastIndexOf('.');
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
prefix = filename + "-";
|
prefix = filename + "-";
|
||||||
} else {
|
} else {
|
||||||
@ -596,16 +596,17 @@ public class ApiClient {
|
|||||||
|
|
||||||
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
||||||
|
|
||||||
for (String key : headerParams.keySet()) {
|
for (Entry<String, String> entry : headerParams.entrySet()) {
|
||||||
String value = headerParams.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(entry.getKey(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key : defaultHeaderMap.keySet()) {
|
for (Entry<String, String> entry : defaultHeaderMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
if (!headerParams.containsKey(key)) {
|
if (!headerParams.containsKey(key)) {
|
||||||
String value = defaultHeaderMap.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(key, value);
|
||||||
}
|
}
|
||||||
@ -614,7 +615,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
Entity<?> entity = serialize(body, formParams, contentType);
|
Entity<?> entity = serialize(body, formParams, contentType);
|
||||||
|
|
||||||
Response response = null;
|
Response response;
|
||||||
|
|
||||||
if ("GET".equals(method)) {
|
if ("GET".equals(method)) {
|
||||||
response = invocationBuilder.get();
|
response = invocationBuilder.get();
|
||||||
@ -635,7 +636,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
||||||
return null;
|
return null;
|
||||||
} else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
|
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
|
||||||
if (returnType == null)
|
if (returnType == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Hello world!
|
|
@ -324,7 +324,7 @@ public class ApiClient {
|
|||||||
StringBuilder b = new StringBuilder();
|
StringBuilder b = new StringBuilder();
|
||||||
for(Object o : (Collection)param) {
|
for(Object o : (Collection)param) {
|
||||||
if(b.length() > 0) {
|
if(b.length() > 0) {
|
||||||
b.append(",");
|
b.append(',');
|
||||||
}
|
}
|
||||||
b.append(String.valueOf(o));
|
b.append(String.valueOf(o));
|
||||||
}
|
}
|
||||||
@ -343,7 +343,7 @@ public class ApiClient {
|
|||||||
// preconditions
|
// preconditions
|
||||||
if (name == null || name.isEmpty() || value == null) return params;
|
if (name == null || name.isEmpty() || value == null) return params;
|
||||||
|
|
||||||
Collection valueCollection = null;
|
Collection valueCollection;
|
||||||
if (value instanceof Collection) {
|
if (value instanceof Collection) {
|
||||||
valueCollection = (Collection) value;
|
valueCollection = (Collection) value;
|
||||||
} else {
|
} else {
|
||||||
@ -356,10 +356,10 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the collection format
|
// get the collection format
|
||||||
collectionFormat = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
String format = (collectionFormat == null || collectionFormat.isEmpty() ? "csv" : collectionFormat); // default: csv
|
||||||
|
|
||||||
// create the params based on the collection format
|
// create the params based on the collection format
|
||||||
if (collectionFormat.equals("multi")) {
|
if ("multi".equals(format)) {
|
||||||
for (Object item : valueCollection) {
|
for (Object item : valueCollection) {
|
||||||
params.add(new Pair(name, parameterToString(item)));
|
params.add(new Pair(name, parameterToString(item)));
|
||||||
}
|
}
|
||||||
@ -369,13 +369,13 @@ public class ApiClient {
|
|||||||
|
|
||||||
String delimiter = ",";
|
String delimiter = ",";
|
||||||
|
|
||||||
if (collectionFormat.equals("csv")) {
|
if ("csv".equals(format)) {
|
||||||
delimiter = ",";
|
delimiter = ",";
|
||||||
} else if (collectionFormat.equals("ssv")) {
|
} else if ("ssv".equals(format)) {
|
||||||
delimiter = " ";
|
delimiter = " ";
|
||||||
} else if (collectionFormat.equals("tsv")) {
|
} else if ("tsv".equals(format)) {
|
||||||
delimiter = "\t";
|
delimiter = "\t";
|
||||||
} else if (collectionFormat.equals("pipes")) {
|
} else if ("pipes".equals(format)) {
|
||||||
delimiter = "|";
|
delimiter = "|";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -459,7 +459,7 @@ public class ApiClient {
|
|||||||
* Content-Type (only JSON is supported for now).
|
* Content-Type (only JSON is supported for now).
|
||||||
*/
|
*/
|
||||||
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
|
||||||
Entity<?> entity = null;
|
Entity<?> entity;
|
||||||
if (contentType.startsWith("multipart/form-data")) {
|
if (contentType.startsWith("multipart/form-data")) {
|
||||||
MultiPart multiPart = new MultiPart();
|
MultiPart multiPart = new MultiPart();
|
||||||
for (Entry<String, Object> param: formParams.entrySet()) {
|
for (Entry<String, Object> param: formParams.entrySet()) {
|
||||||
@ -490,6 +490,7 @@ public class ApiClient {
|
|||||||
/**
|
/**
|
||||||
* Deserialize response body to Java object according to the Content-Type.
|
* Deserialize response body to Java object according to the Content-Type.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
public <T> T deserialize(Response response, GenericType<T> returnType) throws ApiException {
|
||||||
if (response == null || returnType == null) {
|
if (response == null || returnType == null) {
|
||||||
return null;
|
return null;
|
||||||
@ -498,9 +499,8 @@ public class ApiClient {
|
|||||||
if ("byte[]".equals(returnType.toString())) {
|
if ("byte[]".equals(returnType.toString())) {
|
||||||
// Handle binary response (byte array).
|
// Handle binary response (byte array).
|
||||||
return (T) response.readEntity(byte[].class);
|
return (T) response.readEntity(byte[].class);
|
||||||
} else if (returnType.equals(File.class)) {
|
} else if (returnType.getRawType() == File.class) {
|
||||||
// Handle file downloading.
|
// Handle file downloading.
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
T file = (T) downloadFileFromResponse(response);
|
T file = (T) downloadFileFromResponse(response);
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
@ -540,13 +540,13 @@ public class ApiClient {
|
|||||||
filename = matcher.group(1);
|
filename = matcher.group(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String prefix = null;
|
String prefix;
|
||||||
String suffix = null;
|
String suffix = null;
|
||||||
if (filename == null) {
|
if (filename == null) {
|
||||||
prefix = "download-";
|
prefix = "download-";
|
||||||
suffix = "";
|
suffix = "";
|
||||||
} else {
|
} else {
|
||||||
int pos = filename.lastIndexOf(".");
|
int pos = filename.lastIndexOf('.');
|
||||||
if (pos == -1) {
|
if (pos == -1) {
|
||||||
prefix = filename + "-";
|
prefix = filename + "-";
|
||||||
} else {
|
} else {
|
||||||
@ -596,16 +596,17 @@ public class ApiClient {
|
|||||||
|
|
||||||
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
Invocation.Builder invocationBuilder = target.request().accept(accept);
|
||||||
|
|
||||||
for (String key : headerParams.keySet()) {
|
for (Entry<String, String> entry : headerParams.entrySet()) {
|
||||||
String value = headerParams.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(entry.getKey(), value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String key : defaultHeaderMap.keySet()) {
|
for (Entry<String, String> entry : defaultHeaderMap.entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
if (!headerParams.containsKey(key)) {
|
if (!headerParams.containsKey(key)) {
|
||||||
String value = defaultHeaderMap.get(key);
|
String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
invocationBuilder = invocationBuilder.header(key, value);
|
invocationBuilder = invocationBuilder.header(key, value);
|
||||||
}
|
}
|
||||||
@ -614,7 +615,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
Entity<?> entity = serialize(body, formParams, contentType);
|
Entity<?> entity = serialize(body, formParams, contentType);
|
||||||
|
|
||||||
Response response = null;
|
Response response;
|
||||||
|
|
||||||
if ("GET".equals(method)) {
|
if ("GET".equals(method)) {
|
||||||
response = invocationBuilder.get();
|
response = invocationBuilder.get();
|
||||||
@ -635,7 +636,7 @@ public class ApiClient {
|
|||||||
|
|
||||||
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
if (response.getStatus() == Status.NO_CONTENT.getStatusCode()) {
|
||||||
return null;
|
return null;
|
||||||
} else if (response.getStatusInfo().getFamily().equals(Status.Family.SUCCESSFUL)) {
|
} else if (response.getStatusInfo().getFamily() == Status.Family.SUCCESSFUL) {
|
||||||
if (returnType == null)
|
if (returnType == null)
|
||||||
return null;
|
return null;
|
||||||
else
|
else
|
||||||
|
@ -1 +0,0 @@
|
|||||||
Hello world!
|
|
Loading…
x
Reference in New Issue
Block a user