forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 5.2.x
This commit is contained in:
@@ -21,6 +21,8 @@ src/main/kotlin/org/openapitools/client/infrastructure/ApiAbstractions.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApiClient.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApiInfrastructureResponse.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ApplicationDelegates.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/BigDecimalAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/BigIntegerAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/ByteArrayAdapter.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/Errors.kt
|
||||
src/main/kotlin/org/openapitools/client/infrastructure/LocalDateAdapter.kt
|
||||
|
||||
@@ -13,7 +13,10 @@ import okhttp3.Request
|
||||
import okhttp3.Headers
|
||||
import okhttp3.MultipartBody
|
||||
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
|
||||
@@ -114,6 +117,15 @@ open class ApiClient(val baseUrl: String) {
|
||||
if (bodyContent.isEmpty()) {
|
||||
return null
|
||||
}
|
||||
if (T::class.java == File::class.java) {
|
||||
// return tempfile
|
||||
val f = Files.createTempFile("tmp.org.openapitools.client", null).toFile()
|
||||
f.deleteOnExit()
|
||||
val out = BufferedWriter(FileWriter(f))
|
||||
out.write(bodyContent)
|
||||
out.close()
|
||||
return f as T
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigDecimal
|
||||
|
||||
class BigDecimalAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: BigDecimal): String {
|
||||
return value.toPlainString()
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): BigDecimal {
|
||||
return BigDecimal(value)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.openapitools.client.infrastructure
|
||||
|
||||
import com.squareup.moshi.FromJson
|
||||
import com.squareup.moshi.ToJson
|
||||
import java.math.BigInteger
|
||||
|
||||
class BigIntegerAdapter {
|
||||
@ToJson
|
||||
fun toJson(value: BigInteger): String {
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
@FromJson
|
||||
fun fromJson(value: String): BigInteger {
|
||||
return BigInteger(value)
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ object Serializer {
|
||||
.add(UUIDAdapter())
|
||||
.add(ByteArrayAdapter())
|
||||
.add(KotlinJsonAdapterFactory())
|
||||
.add(BigDecimalAdapter())
|
||||
.add(BigIntegerAdapter())
|
||||
|
||||
@JvmStatic
|
||||
val moshi: Moshi by lazy {
|
||||
|
||||
Reference in New Issue
Block a user