Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1733
Closed
Open
Issue created Dec 21, 2018 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking