[BUG][Kotlin] Generated Serializer for ApiClient does not support UUID
Created by: dalewking
Description
Generating a Kotlin client for an API that uses UUIDs in the model, the generated ApiClient doesn't work because the generated Moshi serializer does not have a type adapter for UUID. Unfortunately, there is no way to inject the type adapter yourself.
openapi-generator version
4.0.0
OpenAPI declaration file content or url
Any API with UUID should demonstrate the problem, but here is the one I am using. Note that this will only generate compilable code using version 4.0.0 due to bug with allOf.
Command line used for generation
The gradle configuration:
openApiGenerate {
inputSpec = swaggerInput
outputDir = 'build/swagger'
generatorName = 'kotlin'
invokerPackage = 'com.foo.ynab.client'
modelPackage = 'com.foo.ynab.client.model'
apiPackage = 'com.foo.ynab.client.api'
systemProperties = [
dateLibrary : 'joda'
]
}
Steps to reproduce
Generate Kotlin API and try to send message. I get exception:
Exception in thread "main" java.lang.IllegalArgumentException: Platform class java.util.UUID (with no annotations) requires explicit JsonAdapter to be registered
for class java.util.UUID accountId
for class com.foo.ynab.client.model.SaveTransaction transaction
for class com.foo.ynab.client.model.SaveTransactionsWrapper
Suggest a fix
Not a fix but at least allow injection of type adapters into Moshi by dividing the builder from the built instance in Serializer much like the way builder and client are separated in ApiClient like this:
object Serializer {
@JvmStatic
val moshi: Moshi by lazy {
builder.build()
}
@JvmStatic
val builder = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.add(Date::class.java, Rfc3339DateJsonAdapter().nullSafe())
}
This would at least let me inject a JSonAdapter. But it really should be fixed to support uuid by default.