mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-30 12:40:52 +00:00
Fix UUID support (#1746)
* Add custom type adapter to deserialize UUID * Update samples ./bin/kotlin-client-threetenbp.sh ./bin/kotlin-client-string.sh ./bin/kotlin-client-petstore.sh
This commit is contained in:
parent
292d987f15
commit
5d98fc6beb
@ -1,7 +1,11 @@
|
|||||||
package {{packageName}}.infrastructure
|
package {{packageName}}.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
open class ApiClient(val baseUrl: String) {
|
open class ApiClient(val baseUrl: String) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -51,7 +55,12 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
||||||
if(body == null) return null
|
if(body == null) return null
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(body.source())
|
JsonMediaType -> Moshi.Builder().add(object {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
|
}).build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
open class ApiClient(val baseUrl: String) {
|
open class ApiClient(val baseUrl: String) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -51,7 +55,12 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
||||||
if(body == null) return null
|
if(body == null) return null
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(body.source())
|
JsonMediaType -> Moshi.Builder().add(object {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
|
}).build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
open class ApiClient(val baseUrl: String) {
|
open class ApiClient(val baseUrl: String) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -51,7 +55,12 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
||||||
if(body == null) return null
|
if(body == null) return null
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(body.source())
|
JsonMediaType -> Moshi.Builder().add(object {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
|
}).build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
package org.openapitools.client.infrastructure
|
package org.openapitools.client.infrastructure
|
||||||
|
|
||||||
|
import com.squareup.moshi.FromJson
|
||||||
|
import com.squareup.moshi.Moshi
|
||||||
|
import com.squareup.moshi.ToJson
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
open class ApiClient(val baseUrl: String) {
|
open class ApiClient(val baseUrl: String) {
|
||||||
companion object {
|
companion object {
|
||||||
@ -51,7 +55,12 @@ open class ApiClient(val baseUrl: String) {
|
|||||||
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
protected inline fun <reified T: Any?> responseBody(body: ResponseBody?, mediaType: String = JsonMediaType): T? {
|
||||||
if(body == null) return null
|
if(body == null) return null
|
||||||
return when(mediaType) {
|
return when(mediaType) {
|
||||||
JsonMediaType -> Serializer.moshi.adapter(T::class.java).fromJson(body.source())
|
JsonMediaType -> Moshi.Builder().add(object {
|
||||||
|
@ToJson
|
||||||
|
fun toJson(uuid: UUID) = uuid.toString()
|
||||||
|
@FromJson
|
||||||
|
fun fromJson(s: String) = UUID.fromString(s)
|
||||||
|
}).build().adapter(T::class.java).fromJson(body.source())
|
||||||
else -> TODO()
|
else -> TODO()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user