Skip to content
Permalink
Browse files
Merge pull request from GHSA-hpv8-9rq5-hq7w
security: fix CWE-378 CWE-200 CWE-732 - use java.nio.files
  • Loading branch information
frantuma committed Mar 2, 2021
2 parents 987ea7a + 33a1ef4 commit 35adbd552d5f99b3ff1e0e59da228becc85190f2
Showing with 178 additions and 12,652 deletions.
  1. +0 −1 bin/java-petstore-all.sh
  2. +0 −34 bin/java-petstore-jersey2-java6.sh
  3. +1 −1 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java
  4. +0 −1 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaClientCodegen.java
  5. +3 −4 modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/JavaJerseyServerCodegen.java
  6. +4 −3 modules/swagger-codegen/src/main/resources/Java/libraries/jersey2/ApiClient.mustache
  7. +5 −3 modules/swagger-codegen/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache
  8. +4 −3 modules/swagger-codegen/src/main/resources/Java/libraries/resteasy/ApiClient.mustache
  9. +3 −1 modules/swagger-codegen/src/main/resources/finch/api.mustache
  10. +8 −7 modules/swagger-codegen/src/main/resources/kotlin-client/infrastructure/ApiClient.kt.mustache
  11. +0 −4 modules/swagger-codegen/src/test/java/io/swagger/codegen/config/CodegenConfiguratorTest.java
  12. +1 −3 modules/swagger-codegen/src/test/java/io/swagger/codegen/jaxrs/JaxRSServerOptionsTest.java
  13. +0 −1 modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JavaClientOptionsProvider.java
  14. +0 −1 modules/swagger-codegen/src/test/java/io/swagger/codegen/options/JaxRSServerOptionsProvider.java
  15. +3 −2 modules/swagger-codegen/src/test/resources/2_0/templates/Java/libraries/jersey2/ApiClient.mustache
  16. +0 −12 pom.xml
  17. +0 −12 pom.xml.bash
  18. +0 −12 pom.xml.circleci
  19. +0 −12 pom.xml.circleci.java7
  20. +0 −12 pom.xml.ios
  21. +0 −12 pom.xml.jenkins
  22. +0 −12 pom.xml.jenkins.java7
  23. +0 −12 pom.xml.travis
  24. +6 −4 ...les/client/petstore-security-test/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java
  25. +0 −21 samples/client/petstore/java/jersey2-java6/.gitignore
  26. +0 −23 samples/client/petstore/java/jersey2-java6/.swagger-codegen-ignore
  27. +0 −1 samples/client/petstore/java/jersey2-java6/.swagger-codegen/VERSION
  28. +0 −17 samples/client/petstore/java/jersey2-java6/.travis.yml
  29. +0 −198 samples/client/petstore/java/jersey2-java6/README.md
  30. +0 −117 samples/client/petstore/java/jersey2-java6/build.gradle
  31. +0 −27 samples/client/petstore/java/jersey2-java6/build.sbt
  32. +0 −11 samples/client/petstore/java/jersey2-java6/docs/AdditionalPropertiesClass.md
  33. +0 −11 samples/client/petstore/java/jersey2-java6/docs/Animal.md
  34. +0 −9 samples/client/petstore/java/jersey2-java6/docs/AnimalFarm.md
  35. +0 −54 samples/client/petstore/java/jersey2-java6/docs/AnotherFakeApi.md
  36. +0 −10 samples/client/petstore/java/jersey2-java6/docs/ArrayOfArrayOfNumberOnly.md
  37. +0 −10 samples/client/petstore/java/jersey2-java6/docs/ArrayOfNumberOnly.md
  38. +0 −12 samples/client/petstore/java/jersey2-java6/docs/ArrayTest.md
  39. +0 −15 samples/client/petstore/java/jersey2-java6/docs/Capitalization.md
  40. +0 −10 samples/client/petstore/java/jersey2-java6/docs/Cat.md
  41. +0 −11 samples/client/petstore/java/jersey2-java6/docs/Category.md
  42. +0 −10 samples/client/petstore/java/jersey2-java6/docs/ClassModel.md
  43. +0 −10 samples/client/petstore/java/jersey2-java6/docs/Client.md
  44. +0 −10 samples/client/petstore/java/jersey2-java6/docs/Dog.md
  45. +0 −27 samples/client/petstore/java/jersey2-java6/docs/EnumArrays.md
  46. +0 −14 samples/client/petstore/java/jersey2-java6/docs/EnumClass.md
  47. +0 −48 samples/client/petstore/java/jersey2-java6/docs/EnumTest.md
  48. +0 −514 samples/client/petstore/java/jersey2-java6/docs/FakeApi.md
  49. +0 −64 samples/client/petstore/java/jersey2-java6/docs/FakeClassnameTags123Api.md
  50. +0 −22 samples/client/petstore/java/jersey2-java6/docs/FormatTest.md
  51. +0 −11 samples/client/petstore/java/jersey2-java6/docs/HasOnlyReadOnly.md
  52. +0 −22 samples/client/petstore/java/jersey2-java6/docs/Ints.md
  53. +0 −19 samples/client/petstore/java/jersey2-java6/docs/MapTest.md
  54. +0 −12 samples/client/petstore/java/jersey2-java6/docs/MixedPropertiesAndAdditionalPropertiesClass.md
  55. +0 −11 samples/client/petstore/java/jersey2-java6/docs/Model200Response.md
  56. +0 −12 samples/client/petstore/java/jersey2-java6/docs/ModelApiResponse.md
  57. +0 −12 samples/client/petstore/java/jersey2-java6/docs/ModelBoolean.md
  58. +0 −10 samples/client/petstore/java/jersey2-java6/docs/ModelList.md
  59. +0 −10 samples/client/petstore/java/jersey2-java6/docs/ModelReturn.md
  60. +0 −13 samples/client/petstore/java/jersey2-java6/docs/Name.md
  61. +0 −10 samples/client/petstore/java/jersey2-java6/docs/NumberOnly.md
  62. +0 −16 samples/client/petstore/java/jersey2-java6/docs/Numbers.md
  63. +0 −24 samples/client/petstore/java/jersey2-java6/docs/Order.md
  64. +0 −12 samples/client/petstore/java/jersey2-java6/docs/OuterComposite.md
  65. +0 −14 samples/client/petstore/java/jersey2-java6/docs/OuterEnum.md
  66. +0 −24 samples/client/petstore/java/jersey2-java6/docs/Pet.md
  67. +0 −448 samples/client/petstore/java/jersey2-java6/docs/PetApi.md
  68. +0 −11 samples/client/petstore/java/jersey2-java6/docs/ReadOnlyFirst.md
  69. +0 −10 samples/client/petstore/java/jersey2-java6/docs/SpecialModelName.md
  70. +0 −197 samples/client/petstore/java/jersey2-java6/docs/StoreApi.md
  71. +0 −11 samples/client/petstore/java/jersey2-java6/docs/Tag.md
  72. +0 −17 samples/client/petstore/java/jersey2-java6/docs/User.md
  73. +0 −370 samples/client/petstore/java/jersey2-java6/docs/UserApi.md
  74. +0 −52 samples/client/petstore/java/jersey2-java6/git_push.sh
  75. +0 −2 samples/client/petstore/java/jersey2-java6/gradle.properties
  76. BIN samples/client/petstore/java/jersey2-java6/gradle/wrapper/gradle-wrapper.jar
  77. +0 −6 samples/client/petstore/java/jersey2-java6/gradle/wrapper/gradle-wrapper.properties
  78. +0 −160 samples/client/petstore/java/jersey2-java6/gradlew
  79. +0 −90 samples/client/petstore/java/jersey2-java6/gradlew.bat
  80. +0 −283 samples/client/petstore/java/jersey2-java6/pom.xml
  81. +0 −1 samples/client/petstore/java/jersey2-java6/settings.gradle
  82. +0 −3 samples/client/petstore/java/jersey2-java6/src/main/AndroidManifest.xml
  83. +0 −780 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiClient.java
  84. +0 −91 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiException.java
  85. +0 −59 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/ApiResponse.java
  86. +0 −39 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/Configuration.java
  87. +0 −232 ...client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/CustomInstantDeserializer.java
  88. +0 −44 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/JSON.java
  89. +0 −52 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/Pair.java
  90. +0 −32 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/RFC3339DateFormat.java
  91. +0 −55 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/StringUtil.java
  92. +0 −90 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/AnotherFakeApi.java
  93. +0 −648 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeApi.java
  94. +0 −90 ...ient/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/FakeClassnameTags123Api.java
  95. +0 −482 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/PetApi.java
  96. +0 −240 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/StoreApi.java
  97. +0 −460 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/api/UserApi.java
  98. +0 −75 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/auth/ApiKeyAuth.java
  99. +0 −29 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/auth/Authentication.java
  100. +0 −58 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/auth/HttpBasicAuth.java
  101. +0 −39 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/auth/OAuth.java
  102. +0 −18 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/auth/OAuthFlow.java
  103. +0 −132 .../petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/AdditionalPropertiesClass.java
  104. +0 −120 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Animal.java
  105. +0 −65 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/AnimalFarm.java
  106. +0 −101 ...t/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ArrayOfArrayOfNumberOnly.java
  107. +0 −101 ...s/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ArrayOfNumberOnly.java
  108. +0 −163 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ArrayTest.java
  109. +0 −205 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Capitalization.java
  110. +0 −92 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Cat.java
  111. +0 −113 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Category.java
  112. +0 −91 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ClassModel.java
  113. +0 −90 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Client.java
  114. +0 −92 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Dog.java
  115. +0 −193 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/EnumArrays.java
  116. +0 −58 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/EnumClass.java
  117. +0 −327 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/EnumTest.java
  118. +0 −380 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/FormatTest.java
  119. +0 −95 ...les/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/HasOnlyReadOnly.java
  120. +0 −67 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Ints.java
  121. +0 −167 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/MapTest.java
  122. +0 −150 ...sey2-java6/src/main/java/io/swagger/client/model/MixedPropertiesAndAdditionalPropertiesClass.java
  123. +0 −114 ...es/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Model200Response.java
  124. +0 −136 ...es/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ModelApiResponse.java
  125. +0 −57 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ModelBoolean.java
  126. +0 −90 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ModelList.java
  127. +0 −91 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ModelReturn.java
  128. +0 −142 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Name.java
  129. +0 −91 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/NumberOnly.java
  130. +0 −62 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Numbers.java
  131. +0 −243 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Order.java
  132. +0 −137 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterComposite.java
  133. +0 −58 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/OuterEnum.java
  134. +0 −259 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Pet.java
  135. +0 −104 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/ReadOnlyFirst.java
  136. +0 −90 ...es/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/SpecialModelName.java
  137. +0 −113 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/Tag.java
  138. +0 −251 samples/client/petstore/java/jersey2-java6/src/main/java/io/swagger/client/model/User.java
  139. +0 −51 ...es/client/petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/AnotherFakeApiTest.java
  140. +0 −204 samples/client/petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/FakeApiTest.java
  141. +0 −51 .../petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/FakeClassnameTags123ApiTest.java
  142. +0 −170 samples/client/petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/PetApiTest.java
  143. +0 −98 samples/client/petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/StoreApiTest.java
  144. +0 −164 samples/client/petstore/java/jersey2-java6/src/test/java/io/swagger/client/api/UserApiTest.java
  145. +4 −3 samples/client/petstore/java/jersey2-java8/src/main/java/io/swagger/client/ApiClient.java
  146. +4 −3 samples/client/petstore/java/jersey2/src/main/java/io/swagger/client/ApiClient.java
  147. +5 −3 ...s/client/petstore/java/okhttp-gson-parcelableModel/src/main/java/io/swagger/client/ApiClient.java
  148. +5 −3 samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/ApiClient.java
  149. +4 −3 samples/client/petstore/java/resteasy/src/main/java/io/swagger/client/ApiClient.java
  150. +2 −1 samples/client/petstore/java/retrofit2rx/src/test/java/io/swagger/client/api/PetApiTest.java
  151. +8 −7 samples/client/petstore/kotlin-string/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt
  152. +8 −7 ...s/client/petstore/kotlin-threetenbp/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt
  153. +8 −7 samples/client/petstore/kotlin/src/main/kotlin/io/swagger/client/infrastructure/ApiClient.kt
  154. +18 −17 samples/server/petstore/finch/src/main/scala/io/swagger/apis/PetApi.scala
  155. +10 −9 samples/server/petstore/finch/src/main/scala/io/swagger/apis/StoreApi.scala
  156. +18 −17 samples/server/petstore/finch/src/main/scala/io/swagger/apis/UserApi.scala
  157. +18 −17 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/PetApi.scala
  158. +10 −9 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/StoreApi.scala
  159. +18 −17 samples/server/petstore/finch/src/main/scala/io/swagger/petstore/apis/UserApi.scala
@@ -12,7 +12,6 @@
./bin/java-petstore-retrofit2rx2.sh
./bin/java8-petstore-jersey2.sh
./bin/java-petstore-retrofit2-play24.sh
./bin/java-petstore-jersey2-java6.sh
./bin/java-petstore-resttemplate.sh
./bin/java-petstore-resttemplate-withxml.sh
./bin/java-petstore-resteasy.sh

This file was deleted.

@@ -198,7 +198,7 @@ public void processOpts() {
super.processOpts();

if (additionalProperties.containsKey(SUPPORT_JAVA6)) {
this.setSupportJava6(Boolean.valueOf(additionalProperties.get(SUPPORT_JAVA6).toString()));
this.setSupportJava6(false); // JAVA 6 not supported
}
additionalProperties.put(SUPPORT_JAVA6, supportJava6);

@@ -69,7 +69,6 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
cliOptions.add(CliOption.newBoolean(USE_PLAY_WS, "Use Play! Async HTTP client (Play WS API)"));
cliOptions.add(CliOption.newString(PLAY_VERSION, "Version of Play! Framework (possible values \"play24\", \"play25\")"));
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1 library."));
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
@@ -13,7 +13,7 @@

protected static final String LIBRARY_JERSEY1 = "jersey1";
protected static final String LIBRARY_JERSEY2 = "jersey2";

/**
* Default library template to use. (Default:{@value #DEFAULT_LIBRARY})
*/
@@ -48,7 +48,6 @@ public JavaJerseyServerCodegen() {
library.setDefault(DEFAULT_LIBRARY);

cliOptions.add(library);
cliOptions.add(CliOption.newBoolean(SUPPORT_JAVA6, "Whether to support Java6 with the Jersey1/2 library."));
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames"));
}

@@ -89,11 +88,11 @@ public void processOpts() {
if (StringUtils.isEmpty(library)) {
setLibrary(DEFAULT_LIBRARY);
}

if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
implFolder = (String) additionalProperties.get(CodegenConstants.IMPL_FOLDER);
}

if (additionalProperties.containsKey(USE_TAGS)) {
this.setUseTags(Boolean.valueOf(additionalProperties.get(USE_TAGS).toString()));
}
@@ -25,6 +25,7 @@ import java.io.InputStream;

{{^supportJava6}}
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.glassfish.jersey.logging.LoggingFeature;
{{/supportJava6}}
@@ -296,7 +297,7 @@ public class ApiClient {
public int getReadTimeout() {
return readTimeout;
}

/**
* Set the read timeout (in milliseconds).
* A value of 0 means no timeout, otherwise values must be between 1 and
@@ -628,9 +629,9 @@ public class ApiClient {
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
return Files.createTempFile(prefix, suffix).toFile();
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
}

/**
@@ -24,6 +24,8 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.lang.reflect.Type;
import java.net.URLConnection;
import java.net.URLEncoder;
@@ -829,9 +831,9 @@ public class ApiClient {
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
return Files.createTempFile(prefix, suffix).toFile();
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
}

/**
@@ -981,7 +983,7 @@ public class ApiClient {
* @param formParams The form parameters
* @param authNames The authentications to apply
* @param progressRequestListener Progress request listener
* @return The HTTP request
* @return The HTTP request
* @throws ApiException If fail to serialize the request body object
*/
public Request buildRequest(String path, String method, List<Pair> queryParams, List<Pair> collectionQueryParams, Object body, Map<String, String> headerParams, Map<String, Object> formParams, String[] authNames, ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
@@ -8,6 +8,7 @@ import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -446,7 +447,7 @@ public class ApiClient {
public Entity<?> serialize(Object obj, Map<String, Object> formParams, String contentType) throws ApiException {
Entity<?> entity = null;
if (contentType.startsWith("multipart/form-data")) {
MultipartFormDataOutput multipart = new MultipartFormDataOutput();
MultipartFormDataOutput multipart = new MultipartFormDataOutput();
//MultiPart multiPart = new MultiPart();
for (Entry<String, Object> param: formParams.entrySet()) {
if (param.getValue() instanceof File) {
@@ -552,9 +553,9 @@ public class ApiClient {
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
return Files.createTempFile(prefix, suffix).toFile();
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
}

/**
@@ -16,6 +16,8 @@ import com.twitter.util.Future
import com.twitter.io.Buf
import io.finch._, items._
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.time._

object {{classname}} {
@@ -81,7 +83,7 @@ object {{classname}} {
}

private def bytesToFile(input: Array[Byte]): java.io.File = {
val file = File.createTempFile("tmp{{classname}}", null)
val file = Files.createTempFile("tmp{{classname}}", null).toFile()
val output = new FileOutputStream(file)
output.write(input)
file
@@ -3,6 +3,7 @@ package {{packageName}}.infrastructure
import okhttp3.*
import java.io.File
import java.io.IOException
import java.nio.file.Files;
import java.util.regex.Pattern

open class ApiClient(val baseUrl: String) {
@@ -64,15 +65,15 @@ open class ApiClient(val baseUrl: String) {
inline protected fun <reified T: Any?> responseBody(response: Response, mediaType: String = JsonMediaType): T? {
if(response.body() == null) return null
if(T::class.java == java.io.File::class.java){
return downloadFileFromResponse(response) as T
} else if(T::class == kotlin.Unit::class) {
return kotlin.Unit as T
}
var contentType = response.headers().get("Content-Type")
if(contentType == null) {
contentType = JsonMediaType
}
@@ -85,7 +86,7 @@ open class ApiClient(val baseUrl: String) {
TODO("Fill in more types!")
}
}
fun isJsonMime(mime: String?): Boolean {
val jsonMime = "(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$"
return mime != null && (mime.matches(jsonMime.toRegex()) || mime == "*/*")
@@ -162,7 +163,7 @@ open class ApiClient(val baseUrl: String) {
)
}
}
@Throws(IOException::class)
fun downloadFileFromResponse(response: Response): File {
val file = prepareDownloadFile(response)
@@ -206,6 +207,6 @@ open class ApiClient(val baseUrl: String) {
prefix = "download-"
}

return File.createTempFile(prefix, suffix);
return Files.createTempFile(prefix, suffix).toFile();
}
}
}
@@ -162,14 +162,12 @@ public void testAdditionalProperties() throws Exception {

configurator.addAdditionalProperty("foo", "bar")
.addAdditionalProperty("hello", "world")
.addAdditionalProperty("supportJava6", false)
.addAdditionalProperty("useRxJava", true);

final ClientOptInput clientOptInput = setupAndRunGenericTest(configurator);

assertValueInMap(clientOptInput.getConfig().additionalProperties(), "foo", "bar");
assertValueInMap(clientOptInput.getConfig().additionalProperties(), "hello", "world");
assertValueInMap(clientOptInput.getConfig().additionalProperties(), "supportJava6", false);
assertValueInMap(clientOptInput.getConfig().additionalProperties(), "useRxJava", true);
}

@@ -250,13 +248,11 @@ public void testLibrary() throws Exception {
@Test
public void testDynamicProperties() throws Exception {
configurator.addDynamicProperty(CodegenConstants.LOCAL_VARIABLE_PREFIX, "_");
configurator.addDynamicProperty("supportJava6", false);
configurator.addDynamicProperty("useRxJava", true);

final ClientOptInput clientOptInput = setupAndRunGenericTest(configurator);

assertValueInMap(clientOptInput.getConfig().additionalProperties(), CodegenConstants.LOCAL_VARIABLE_PREFIX, "_");
assertValueInMap(clientOptInput.getConfig().additionalProperties(), "supportJava6", false);
assertValueInMap(clientOptInput.getConfig().additionalProperties(), "useRxJava", true);
}

@@ -72,10 +72,8 @@ protected void setExpectations() {
times = 1;
clientCodegen.setDateLibrary("joda");
times = 1;
clientCodegen.setSupportJava6(false);
times = 1;
clientCodegen.setUseBeanValidation(Boolean.valueOf(JaxRSServerOptionsProvider.USE_BEANVALIDATION));
times = 1;
times = 1;
clientCodegen.setUseTags(Boolean.valueOf(JaxRSServerOptionsProvider.USE_TAGS));
times = 1;
}};
@@ -21,7 +21,6 @@
options.put(JavaClientCodegen.USE_PLAY_WS, "false");
options.put(JavaClientCodegen.PLAY_VERSION, JavaClientCodegen.PLAY_25);
options.put(JavaClientCodegen.PARCELABLE_MODEL, "false");
options.put(JavaClientCodegen.SUPPORT_JAVA6, "false");
options.put(JavaClientCodegen.USE_BEANVALIDATION, "false");
options.put(JavaClientCodegen.PERFORM_BEANVALIDATION, PERFORM_BEANVALIDATION);
options.put(JavaClientCodegen.USE_GZIP_FEATURE, "false");
@@ -58,7 +58,6 @@ public String getLanguage() {
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
builder.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
.put(JavaClientCodegen.DATE_LIBRARY, "joda") //java.lang.IllegalArgumentException: Multiple entries with same key: dateLibrary=joda and dateLibrary=joda
.put(JavaClientCodegen.SUPPORT_JAVA6, "false")
.put("title", "Test title")
.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
.put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
@@ -27,6 +27,7 @@ import java.io.InputStream;

{{^supportJava6}}
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
{{/supportJava6}}
{{#supportJava6}}
@@ -624,9 +625,9 @@ public class ApiClient {
}

if (tempFolderPath == null)
return File.createTempFile(prefix, suffix);
return Files.createTempFile(prefix, suffix).toFile();
else
return File.createTempFile(prefix, suffix, new File(tempFolderPath));
return Files.createTempFile(Paths.get(tempFolderPath), prefix, suffix).toFile();
}

/**
12 pom.xml
@@ -408,18 +408,6 @@
<module>samples/client/petstore/java/jersey2</module>
</modules>
</profile>
<profile>
<id>java-client-jersey2-java6</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/java/jersey2-java6</module>
</modules>
</profile>
<profile>
<id>java-client-okhttp-gson</id>
<activation>
@@ -408,18 +408,6 @@
<module>samples/client/petstore/java/jersey2</module>
</modules>
</profile>
<profile>
<id>java-client-jersey2-java6</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/java/jersey2-java6</module>
</modules>
</profile>
<profile>
<id>java-client-okhttp-gson</id>
<activation>
@@ -368,18 +368,6 @@
<module>samples/client/petstore/java/jersey2</module>
</modules>
</profile>
<profile>
<id>java-client-jersey2-java6</id>
<activation>
<property>
<name>env</name>
<value>java</value>
</property>
</activation>
<modules>
<module>samples/client/petstore/java/jersey2-java6</module>
</modules>
</profile>
<profile>
<id>java-client-okhttp-gson</id>
<activation>

0 comments on commit 35adbd5

Please sign in to comment.