[Kotlin][Client] replace java.nio.* to avoid crash on Android API 25 and bellow (#12529)

* [Kotlin][Client] replace java.nio.* to avoid crash on Android API 25 and bellow

* [Kotlin][Client] update sample projects

* [Kotlin][Client] update sample projects
This commit is contained in:
Bruno Coelho 2022-06-04 09:26:59 +01:00 committed by GitHub
parent 45a3b15b69
commit fe8187ba6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 181 additions and 101 deletions

View File

@ -206,22 +206,26 @@ import com.squareup.moshi.adapter
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
{{^supportAndroidApiLevel25AndBelow}} {{^supportAndroidApiLevel25AndBelow}}
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.{{packageName}}", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.{{packageName}}", null).toFile()
{{/supportAndroidApiLevel25AndBelow}} {{/supportAndroidApiLevel25AndBelow}}
{{#supportAndroidApiLevel25AndBelow}} {{#supportAndroidApiLevel25AndBelow}}
val f = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val tempFile = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile() java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile()
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null) createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null)
} }
{{/supportAndroidApiLevel25AndBelow}} {{/supportAndroidApiLevel25AndBelow}}
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -116,12 +116,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -116,12 +116,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -117,12 +117,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -117,12 +117,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -119,16 +119,20 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
val f = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val tempFile = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile() java.nio.file.Files.createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null).toFile()
} else { } else {
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null) createTempFile("tmp.net.medicineone.teleconsultationandroid.openapi.openapicommon", null)
} }
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -120,12 +120,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ internal open class ApiClient(val baseUrl: String, val client: OkHttpClient = de
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -116,12 +116,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {

View File

@ -118,12 +118,16 @@ open class ApiClient(val baseUrl: String, val client: OkHttpClient = defaultClie
return null return null
} }
if (T::class.java == File::class.java) { if (T::class.java == File::class.java) {
// return tempfile // return tempFile
// Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options // Attention: if you are developing an android app that supports API Level 25 and bellow, please check flag supportAndroidApiLevel25AndBelow in https://openapi-generator.tech/docs/generators/kotlin#config-options
val f = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile() val tempFile = java.nio.file.Files.createTempFile("tmp.org.openapitools.client", null).toFile()
f.deleteOnExit() tempFile.deleteOnExit()
body.byteStream().use { java.nio.file.Files.copy(it, f.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING) } body.byteStream().use { inputStream ->
return f as T tempFile.outputStream().use { tempFileOutputStream ->
inputStream.copyTo(tempFileOutputStream)
}
}
return tempFile as T
} }
val bodyContent = body.string() val bodyContent = body.string()
if (bodyContent.isEmpty()) { if (bodyContent.isEmpty()) {