From e6af83efd39edbd10d0a6f42647c28c94862802d Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Tue, 25 May 2021 14:57:43 +0100 Subject: [PATCH 1/6] [kotlin][client] fix Android crash on API level --- .../libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- 12 files changed, 12 insertions(+), 24 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index aa5a275a9f37..37bf6e080451 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -28,7 +28,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date {{^threetenbp}} import java.time.LocalDate @@ -176,7 +175,7 @@ import org.threeten.bp.OffsetTime } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.{{packageName}}", null).toFile() + val f = createTempFile("tmp.{{packageName}}", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8ffe54035961..5f8d07a6bab8 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 0ea33dc522cc..87c1589880dd 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index cd2898923dd3..7a6dde4e6220 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8ffe54035961..5f8d07a6bab8 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bc9ed02c0f16..9dffb944e8d7 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d43c0c614d57..ab7c8717c293 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ internal open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bc9ed02c0f16..9dffb944e8d7 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 8fad7b08960f..ddd89dbb9dea 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -14,7 +14,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -117,7 +116,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bc9ed02c0f16..9dffb944e8d7 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bd6833418965..d9ec7b1a40c9 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import org.threeten.bp.LocalDate import org.threeten.bp.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index a9f5f6ce2a23..6152456ca9ad 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) From c75da9c10f404fe9dfc85ca282817c759dbc883a Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Tue, 25 May 2021 15:17:21 +0100 Subject: [PATCH 2/6] [kotlin][client] update sample project --- .../kotlin/org/openapitools/client/infrastructure/ApiClient.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index bc9ed02c0f16..9dffb944e8d7 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -16,7 +16,6 @@ import java.io.File import java.io.BufferedWriter import java.io.FileWriter import java.net.URLConnection -import java.nio.file.Files import java.util.Date import java.time.LocalDate import java.time.LocalDateTime @@ -119,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile() + val f = createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) From b86d5fb46a1d6f13658bce0bf3b043e42f40ca7f Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Tue, 25 May 2021 15:31:10 +0100 Subject: [PATCH 3/6] Try to fix CI --- docs/generators/tiny-cpp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/generators/tiny-cpp.md b/docs/generators/tiny-cpp.md index cd3877236ec7..f7f6a0385cac 100644 --- a/docs/generators/tiny-cpp.md +++ b/docs/generators/tiny-cpp.md @@ -165,7 +165,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Maps|✗|ToolingExtension |CollectionFormat|✓|OAS2 |CollectionFormatMulti|✓|OAS2 -|Enum|✓|OAS2,OAS3 +|Enum|✗|OAS2,OAS3 |ArrayOfEnum|✓|ToolingExtension |ArrayOfModel|✓|ToolingExtension |ArrayOfCollectionOfPrimitives|✓|ToolingExtension From 7c19d07973f76d6d45a11e08b2b8da461a4a4710 Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Tue, 25 May 2021 18:27:21 +0100 Subject: [PATCH 4/6] [kotlin][client] add flag to control android api level supported --- bin/configs/kotlin-json-request-string.yaml | 1 + docs/generators/tiny-cpp.md | 2 +- .../codegen/languages/KotlinClientCodegen.java | 4 ++++ .../infrastructure/ApiClient.kt.mustache | 15 ++++++++++++++- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 8 +++++++- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- .../client/infrastructure/ApiClient.kt | 2 +- 16 files changed, 38 insertions(+), 14 deletions(-) diff --git a/bin/configs/kotlin-json-request-string.yaml b/bin/configs/kotlin-json-request-string.yaml index 375622ae5df0..bbe5ddd4283b 100644 --- a/bin/configs/kotlin-json-request-string.yaml +++ b/bin/configs/kotlin-json-request-string.yaml @@ -6,3 +6,4 @@ additionalProperties: requestDateConverter: toString artifactId: kotlin-petstore-json-request-string parcelizeModels: true + supportAndroidApiLevel25AndBelow: true diff --git a/docs/generators/tiny-cpp.md b/docs/generators/tiny-cpp.md index f7f6a0385cac..cd3877236ec7 100644 --- a/docs/generators/tiny-cpp.md +++ b/docs/generators/tiny-cpp.md @@ -165,7 +165,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Maps|✗|ToolingExtension |CollectionFormat|✓|OAS2 |CollectionFormatMulti|✓|OAS2 -|Enum|✗|OAS2,OAS3 +|Enum|✓|OAS2,OAS3 |ArrayOfEnum|✓|ToolingExtension |ArrayOfModel|✓|ToolingExtension |ArrayOfCollectionOfPrimitives|✓|ToolingExtension diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index d2a229fe9888..383594b9ea42 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -63,6 +63,8 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen { public static final String MOSHI_CODE_GEN = "moshiCodeGen"; + public static final String SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW = "supportAndroidApiLevel25AndBelow"; + protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal"; protected String dateLibrary = DateLibrary.JAVA8.value; @@ -208,6 +210,8 @@ public KotlinClientCodegen() { cliOptions.add(CliOption.newBoolean(USE_COROUTINES, "Whether to use the Coroutines adapter with the retrofit2 library.")); cliOptions.add(CliOption.newBoolean(MOSHI_CODE_GEN, "Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info.")); + + cliOptions.add(CliOption.newBoolean(SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW, "[WARNING] This flag with generate code that has as a know security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284")); } public CodegenType getTag() { diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache index 37bf6e080451..b470beae2e5d 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-okhttp/infrastructure/ApiClient.kt.mustache @@ -1,5 +1,8 @@ package {{packageName}}.infrastructure +{{#supportAndroidApiLevel25AndBelow}} +import android.os.Build +{{/supportAndroidApiLevel25AndBelow}} import okhttp3.Credentials import okhttp3.OkHttpClient import okhttp3.RequestBody @@ -175,7 +178,17 @@ import org.threeten.bp.OffsetTime } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.{{packageName}}", null).toFile() + {{^supportAndroidApiLevel25AndBelow}} + val f = java.nio.file.Files.createTempFile("tmp.{{packageName}}", null).toFile() + {{/supportAndroidApiLevel25AndBelow}} + {{#supportAndroidApiLevel25AndBelow}} + val f = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile() + } else { + @Suppress("DEPRECATION") + createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null) + } + {{/supportAndroidApiLevel25AndBelow}} f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5f8d07a6bab8..a1c98200ac47 100644 --- a/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-gson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 87c1589880dd..e9bcbc7981c3 100644 --- a/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jackson/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 7a6dde4e6220..a9fe6b46d778 100644 --- a/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-json-request-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -1,5 +1,6 @@ package org.openapitools.client.infrastructure +import android.os.Build import okhttp3.Credentials import okhttp3.OkHttpClient import okhttp3.RequestBody @@ -118,7 +119,12 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile() + } else { + @Suppress("DEPRECATION") + createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null) + } f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 5f8d07a6bab8..a1c98200ac47 100644 --- a/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-jvm-okhttp4-coroutines/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9dffb944e8d7..c548762e28be 100644 --- a/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-moshi-codegen/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ab7c8717c293..98b12a971509 100644 --- a/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nonpublic/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ internal open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9dffb944e8d7..c548762e28be 100644 --- a/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-nullable/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index ddd89dbb9dea..72929a5dc0fc 100644 --- a/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-okhttp3/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -116,7 +116,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9dffb944e8d7..c548762e28be 100644 --- a/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-string/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index d9ec7b1a40c9..12ea3e7c065e 100644 --- a/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-threetenbp/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 6152456ca9ad..9da041200e1c 100644 --- a/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin-uppercase-enum/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) diff --git a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt index 9dffb944e8d7..c548762e28be 100644 --- a/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt +++ b/samples/client/petstore/kotlin/src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt @@ -118,7 +118,7 @@ open class ApiClient(val baseUrl: String) { } if (T::class.java == File::class.java) { // return tempfile - val f = createTempFile("tmp.org.openapitools.client", null).toFile() + val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() f.deleteOnExit() val out = BufferedWriter(FileWriter(f)) out.write(bodyContent) From 49eb59430b6f49a98577e6b5032cc7a59386bff5 Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Tue, 25 May 2021 20:21:01 +0100 Subject: [PATCH 5/6] [kotlin][client] update docs --- docs/generators/kotlin.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generators/kotlin.md b/docs/generators/kotlin.md index f4b0aceeb60a..7f6d5907712b 100644 --- a/docs/generators/kotlin.md +++ b/docs/generators/kotlin.md @@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null| |sourceFolder|source folder for generated code| |src/main/kotlin| +|supportAndroidApiLevel25AndBelow|[WARNING] This flag with generate code that has as a know security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284| |false| |useCoroutines|Whether to use the Coroutines adapter with the retrofit2 library.| |false| |useRxJava|Whether to use the RxJava adapter with the retrofit2 library.| |false| |useRxJava2|Whether to use the RxJava2 adapter with the retrofit2 library.| |false| From 686e1c4f2ca9c574dae1bd996d64809dedc0fb2a Mon Sep 17 00:00:00 2001 From: Bruno Coelho <4brunu@gmail.com> Date: Wed, 26 May 2021 10:05:13 +0100 Subject: [PATCH 6/6] [kotlin][client] update docs --- docs/generators/kotlin.md | 2 +- .../org/openapitools/codegen/languages/KotlinClientCodegen.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/generators/kotlin.md b/docs/generators/kotlin.md index 7f6d5907712b..6432fc5be67a 100644 --- a/docs/generators/kotlin.md +++ b/docs/generators/kotlin.md @@ -25,7 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |sortModelPropertiesByRequiredFlag|Sort model properties to place required parameters before optional parameters.| |null| |sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |null| |sourceFolder|source folder for generated code| |src/main/kotlin| -|supportAndroidApiLevel25AndBelow|[WARNING] This flag with generate code that has as a know security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284| |false| +|supportAndroidApiLevel25AndBelow|[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284| |false| |useCoroutines|Whether to use the Coroutines adapter with the retrofit2 library.| |false| |useRxJava|Whether to use the RxJava adapter with the retrofit2 library.| |false| |useRxJava2|Whether to use the RxJava2 adapter with the retrofit2 library.| |false| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java index 383594b9ea42..c98ffd60e72e 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinClientCodegen.java @@ -211,7 +211,7 @@ public KotlinClientCodegen() { cliOptions.add(CliOption.newBoolean(MOSHI_CODE_GEN, "Whether to enable codegen with the Moshi library. Refer to the [official Moshi doc](https://github.com/square/moshi#codegen) for more info.")); - cliOptions.add(CliOption.newBoolean(SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW, "[WARNING] This flag with generate code that has as a know security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284")); + cliOptions.add(CliOption.newBoolean(SUPPORT_ANDROID_API_LEVEL_25_AND_BELLOW, "[WARNING] This flag will generate code that has a known security vulnerability. It uses `kotlin.io.createTempFile` instead of `java.nio.file.Files.createTempFile` in oder to support Android API level 25 and bellow. For more info, please check the following links https://github.com/OpenAPITools/openapi-generator/security/advisories/GHSA-23x4-m842-fmwf, https://github.com/OpenAPITools/openapi-generator/pull/9284")); } public CodegenType getTag() {