Merge remote-tracking branch 'origin/master' into 2.3.0

This commit is contained in:
wing328
2016-11-09 16:37:11 +08:00
158 changed files with 1842 additions and 1165 deletions

View File

@@ -5,9 +5,7 @@ import java.util.Map;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.AuthenticationRequestBuilder;
import org.apache.oltu.oauth2.client.request.OAuthClientRequest.TokenRequestBuilder;
import org.threeten.bp.Instant;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.ZonedDateTime;
import org.threeten.bp.*;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -16,6 +14,7 @@ import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule;
import feign.Feign;
import feign.RequestInterceptor;
import feign.form.FormEncoder;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import feign.slf4j.Slf4jLogger;
@@ -35,7 +34,7 @@ public class ApiClient {
objectMapper = createObjectMapper();
apiAuthorizations = new LinkedHashMap<String, RequestInterceptor>();
feignBuilder = Feign.builder()
.encoder(new FormAwareEncoder(new JacksonEncoder(objectMapper)))
.encoder(new FormEncoder(new JacksonEncoder(objectMapper)))
.decoder(new JacksonDecoder(objectMapper))
.logger(new Slf4jLogger());
}

View File

@@ -1,192 +0,0 @@
package io.swagger.client;
import java.io.*;
import java.lang.reflect.Type;
import java.net.URLEncoder;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.*;
import java.text.DateFormat;
import feign.codec.EncodeException;
import feign.codec.Encoder;
import feign.RequestTemplate;
public class FormAwareEncoder implements Encoder {
public static final String UTF_8 = "utf-8";
private static final String LINE_FEED = "\r\n";
private static final String TWO_DASH = "--";
private static final String BOUNDARY = "----------------314159265358979323846";
private byte[] lineFeedBytes;
private byte[] boundaryBytes;
private byte[] twoDashBytes;
private byte[] atBytes;
private byte[] eqBytes;
private final Encoder delegate;
private final DateFormat dateFormat;
public FormAwareEncoder(Encoder delegate) {
this.delegate = delegate;
this.dateFormat = new RFC3339DateFormat();;
try {
this.lineFeedBytes = LINE_FEED.getBytes(UTF_8);
this.boundaryBytes = BOUNDARY.getBytes(UTF_8);
this.twoDashBytes = TWO_DASH.getBytes(UTF_8);
this.atBytes = "&".getBytes(UTF_8);
this.eqBytes = "=".getBytes(UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public void encode(Object object, Type bodyType, RequestTemplate template) throws EncodeException {
if (object instanceof Map) {
try {
encodeFormParams(template, (Map<String, Object>) object);
} catch (IOException e) {
throw new EncodeException("Failed to create request", e);
}
} else {
delegate.encode(object, bodyType, template);
}
}
private void encodeFormParams(RequestTemplate template, Map<String, Object> formParams) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean isMultiPart = isMultiPart(formParams);
boolean isFirstField = true;
for (Map.Entry<String, Object> param : formParams.entrySet()) {
String keyStr = param.getKey();
if (param.getValue() instanceof File) {
addFilePart(baos, keyStr, (File) param.getValue());
} else {
String valueStr = parameterToString(param.getValue());
if (isMultiPart) {
addMultiPartFormField(baos, keyStr, valueStr);
} else {
addEncodedFormField(baos, keyStr, valueStr, isFirstField);
isFirstField = false;
}
}
}
if (isMultiPart) {
baos.write(lineFeedBytes);
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(twoDashBytes);
baos.write(lineFeedBytes);
}
String contentType = isMultiPart ? "multipart/form-data; boundary=" + BOUNDARY : "application/x-www-form-urlencoded";
template.header("Content-type");
template.header("Content-type", contentType);
template.header("MIME-Version", "1.0");
template.body(baos.toByteArray(), Charset.forName(UTF_8));
}
/*
* Currently only supports text files
*/
private void addFilePart(ByteArrayOutputStream baos, String fieldName, File uploadFile) throws IOException {
String fileName = uploadFile.getName();
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
String contentDisposition = "Content-Disposition: form-data; name=\"" + fieldName
+ "\"; filename=\"" + fileName + "\"";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
String contentType = "Content-Type: " + URLConnection.guessContentTypeFromName(fileName);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
BufferedReader reader = new BufferedReader(new FileReader(uploadFile));
InputStream input = new FileInputStream(uploadFile);
byte[] bytes = new byte[4096];
int len = bytes.length;
while ((len = input.read(bytes)) != -1) {
baos.write(bytes, 0, len);
baos.write(lineFeedBytes);
}
baos.write(lineFeedBytes);
}
private void addEncodedFormField(ByteArrayOutputStream baos, String name, String value, boolean isFirstField) throws IOException {
if (!isFirstField) {
baos.write(atBytes);
}
String encodedName = URLEncoder.encode(name, UTF_8);
String encodedValue = URLEncoder.encode(value, UTF_8);
baos.write(encodedName.getBytes(UTF_8));
baos.write("=".getBytes(UTF_8));
baos.write(encodedValue.getBytes(UTF_8));
}
private void addMultiPartFormField(ByteArrayOutputStream baos, String name, String value) throws IOException {
baos.write(twoDashBytes);
baos.write(boundaryBytes);
baos.write(lineFeedBytes);
String contentDisposition = "Content-Disposition: form-data; name=\"" + name + "\"";
String contentType = "Content-Type: text/plain; charset=utf-8";
baos.write(contentDisposition.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(contentType.getBytes(UTF_8));
baos.write(lineFeedBytes);
baos.write(lineFeedBytes);
baos.write(value.getBytes(UTF_8));
baos.write(lineFeedBytes);
}
private boolean isMultiPart(Map<String, Object> formParams) {
boolean isMultiPart = false;
for (Map.Entry<String, Object> entry : formParams.entrySet()) {
if (entry.getValue() instanceof File) {
isMultiPart = true;
break;
}
}
return isMultiPart;
}
/**
* Format the given parameter object into string.
*/
public String parameterToString(Object param) {
if (param == null) {
return "";
} else if (param instanceof Date) {
return formatDate((Date) param);
} else if (param instanceof Collection) {
StringBuilder b = new StringBuilder();
for(Object o : (Collection)param) {
if(b.length() > 0) {
b.append(",");
}
b.append(String.valueOf(o));
}
return b.toString();
} else {
return String.valueOf(param);
}
}
/**
* Format the given Date object into string.
*/
public String formatDate(Date date) {
return dateFormat.format(date);
}
}

View File

@@ -0,0 +1,22 @@
package io.swagger.client;
import feign.Param;
import java.text.DateFormat;
import java.util.Date;
/**
* Param Expander to convert {@link Date} to RFC3339
*/
public class ParamExpander implements Param.Expander {
private static final DateFormat dateformat = new RFC3339DateFormat();
@Override
public String expand(Object value) {
if (value instanceof Date) {
return dateformat.format(value);
}
return value.toString();
}
}

View File

@@ -3,8 +3,8 @@ package io.swagger.client.api;
import io.swagger.client.ApiClient;
import io.swagger.client.model.Client;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
import java.math.BigDecimal;
import java.util.ArrayList;
@@ -25,7 +25,7 @@ public interface FakeApi extends ApiClient.Api {
*/
@RequestLine("PATCH /fake")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
Client testClientModel(Client body);
@@ -51,7 +51,7 @@ public interface FakeApi extends ApiClient.Api {
*/
@RequestLine("POST /fake")
@Headers({
"Content-type: application/xml; charset&#x3D;utf-8",
"Content-Type: application/xml; charset&#x3D;utf-8",
"Accept: application/xml; charset&#x3D;utf-8,application/json; charset&#x3D;utf-8",
})
void testEndpointParameters(@Param("number") BigDecimal number, @Param("_double") Double _double, @Param("patternWithoutDelimiter") String patternWithoutDelimiter, @Param("_byte") byte[] _byte, @Param("integer") Integer integer, @Param("int32") Integer int32, @Param("int64") Long int64, @Param("_float") Float _float, @Param("string") String string, @Param("binary") byte[] binary, @Param("date") LocalDate date, @Param("dateTime") OffsetDateTime dateTime, @Param("password") String password, @Param("paramCallback") String paramCallback);
@@ -71,8 +71,8 @@ public interface FakeApi extends ApiClient.Api {
*/
@RequestLine("GET /fake?enum_query_string_array={enumQueryStringArray}&enum_query_string={enumQueryString}&enum_query_integer={enumQueryInteger}")
@Headers({
"Content-type: application/json",
"Accept: application/json",
"Content-Type: */*",
"Accept: */*",
"enum_header_string_array: {enumHeaderStringArray}",
"enum_header_string: {enumHeaderString}"

View File

@@ -1,29 +0,0 @@
package io.swagger.client.api;
import io.swagger.client.ApiClient;
import io.swagger.client.model.Client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import feign.*;
public interface FakeclassnametagsApi extends ApiClient.Api {
/**
* To test class name in snake case
*
* @param body client model (required)
* @return Client
*/
@RequestLine("PATCH /fake_classname_test")
@Headers({
"Content-type: application/json",
"Accept: application/json",
})
Client testClassname(Client body);
}

View File

@@ -3,8 +3,8 @@ package io.swagger.client.api;
import io.swagger.client.ApiClient;
import io.swagger.client.model.Pet;
import io.swagger.client.model.ModelApiResponse;
import java.io.File;
import io.swagger.client.model.ModelApiResponse;
import java.util.ArrayList;
import java.util.HashMap;
@@ -24,7 +24,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("POST /pet")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void addPet(Pet body);
@@ -38,7 +38,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("DELETE /pet/{petId}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
"api_key: {apiKey}"
})
@@ -52,7 +52,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByStatus?status={status}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByStatus(@Param("status") List<String> status);
@@ -65,7 +65,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/findByTags?tags={tags}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
List<Pet> findPetsByTags(@Param("tags") List<String> tags);
@@ -78,7 +78,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("GET /pet/{petId}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
Pet getPetById(@Param("petId") Long petId);
@@ -91,7 +91,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("PUT /pet")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void updatePet(Pet body);
@@ -106,7 +106,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("POST /pet/{petId}")
@Headers({
"Content-type: application/x-www-form-urlencoded",
"Content-Type: application/x-www-form-urlencoded",
"Accept: application/json",
})
void updatePetWithForm(@Param("petId") Long petId, @Param("name") String name, @Param("status") String status);
@@ -121,7 +121,7 @@ public interface PetApi extends ApiClient.Api {
*/
@RequestLine("POST /pet/{petId}/uploadImage")
@Headers({
"Content-type: multipart/form-data",
"Content-Type: multipart/form-data",
"Accept: application/json",
})
ModelApiResponse uploadFile(@Param("petId") Long petId, @Param("additionalMetadata") String additionalMetadata, @Param("file") File file);

View File

@@ -22,7 +22,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("DELETE /store/order/{orderId}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void deleteOrder(@Param("orderId") String orderId);
@@ -34,7 +34,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("GET /store/inventory")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
Map<String, Integer> getInventory();
@@ -47,7 +47,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("GET /store/order/{orderId}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
Order getOrderById(@Param("orderId") Long orderId);
@@ -60,7 +60,7 @@ public interface StoreApi extends ApiClient.Api {
*/
@RequestLine("POST /store/order")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
Order placeOrder(Order body);

View File

@@ -22,7 +22,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("POST /user")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void createUser(User body);
@@ -35,7 +35,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("POST /user/createWithArray")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void createUsersWithArrayInput(List<User> body);
@@ -48,7 +48,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("POST /user/createWithList")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void createUsersWithListInput(List<User> body);
@@ -61,7 +61,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("DELETE /user/{username}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void deleteUser(@Param("username") String username);
@@ -74,7 +74,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/{username}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
User getUserByName(@Param("username") String username);
@@ -88,7 +88,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/login?username={username}&password={password}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
String loginUser(@Param("username") String username, @Param("password") String password);
@@ -100,7 +100,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("GET /user/logout")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void logoutUser();
@@ -114,7 +114,7 @@ public interface UserApi extends ApiClient.Api {
*/
@RequestLine("PUT /user/{username}")
@Headers({
"Content-type: application/json",
"Content-Type: application/json",
"Accept: application/json",
})
void updateUser(@Param("username") String username, User body);

View File

@@ -110,6 +110,7 @@ public class AdditionalPropertiesClass {
return Objects.hash(mapProperty, mapOfMapProperty);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -97,6 +97,7 @@ public class Animal {
return Objects.hash(className, color);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -52,6 +52,7 @@ public class AnimalFarm extends ArrayList<Animal> {
return Objects.hash(super.hashCode());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -83,6 +83,7 @@ public class ArrayOfArrayOfNumberOnly {
return Objects.hash(arrayArrayNumber);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -83,6 +83,7 @@ public class ArrayOfNumberOnly {
return Objects.hash(arrayNumber);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -137,6 +137,7 @@ public class ArrayTest {
return Objects.hash(arrayOfString, arrayArrayOfInteger, arrayArrayOfModel);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -77,6 +77,7 @@ public class Cat extends Animal {
return Objects.hash(declawed, super.hashCode());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -97,6 +97,7 @@ public class Category {
return Objects.hash(id, name);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -75,6 +75,7 @@ public class Client {
return Objects.hash(client);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -77,6 +77,7 @@ public class Dog extends Animal {
return Objects.hash(breed, super.hashCode());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -164,6 +164,7 @@ public class EnumArrays {
return Objects.hash(justSymbol, arrayEnum);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -209,6 +209,7 @@ public class EnumTest {
return Objects.hash(enumString, enumInteger, enumNumber);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -353,6 +353,7 @@ public class FormatTest {
return Objects.hash(integer, int32, int64, number, _float, _double, string, _byte, binary, date, dateTime, uuid, password);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -79,6 +79,7 @@ public class HasOnlyReadOnly {
return Objects.hash(bar, foo);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -140,6 +140,7 @@ public class MapTest {
return Objects.hash(mapMapOfString, mapOfEnumString);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -130,6 +130,7 @@ public class MixedPropertiesAndAdditionalPropertiesClass {
return Objects.hash(uuid, dateTime, map);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -98,6 +98,7 @@ public class Model200Response {
return Objects.hash(name, propertyClass);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -119,6 +119,7 @@ public class ModelApiResponse {
return Objects.hash(code, type, message);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -76,6 +76,7 @@ public class ModelReturn {
return Objects.hash(_return);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -124,6 +124,7 @@ public class Name {
return Objects.hash(name, snakeCase, property, _123Number);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -76,6 +76,7 @@ public class NumberOnly {
return Objects.hash(justNumber);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -218,6 +218,7 @@ public class Order {
return Objects.hash(id, petId, quantity, shipDate, status, complete);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -231,6 +231,7 @@ public class Pet {
return Objects.hash(id, category, name, photoUrls, tags, status);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -88,6 +88,7 @@ public class ReadOnlyFirst {
return Objects.hash(bar, baz);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -75,6 +75,7 @@ public class SpecialModelName {
return Objects.hash(specialPropertyName);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -97,6 +97,7 @@ public class Tag {
return Objects.hash(id, name);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();

View File

@@ -229,6 +229,7 @@ public class User {
return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus);
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();