mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-03 08:46:55 +00:00
Merge remote-tracking branch 'origin/5.3.x' into 6.0.x
This commit is contained in:
@@ -32,6 +32,7 @@ dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
|
||||
implementation "com.squareup.moshi:moshi-kotlin:1.12.0"
|
||||
implementation "com.squareup.moshi:moshi-adapters:1.12.0"
|
||||
implementation "com.squareup.okhttp3:okhttp:4.9.1"
|
||||
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.time.OffsetDateTime
|
||||
import java.time.OffsetTime
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import com.squareup.moshi.adapter
|
||||
|
||||
open class ApiClient(val baseUrl: String) {
|
||||
companion object {
|
||||
@@ -107,6 +108,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
else -> throw UnsupportedOperationException("requestBody currently only supports JSON body and File body.")
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String? = JsonMediaType): T? {
|
||||
if(body == null) {
|
||||
return null
|
||||
@@ -130,7 +132,7 @@ open class ApiClient(val baseUrl: String) {
|
||||
return f as T
|
||||
}
|
||||
return when(mediaType) {
|
||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(bodyContent)
|
||||
JsonMediaType -> Serializer.moshi.adapter<T>().fromJson(bodyContent)
|
||||
else -> throw UnsupportedOperationException("responseBody currently only supports JSON body.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user