How to customize OffsetDateTime serialization format in openapi-generator for kotlin client

Viewed 374

I'm trying to customise OffsetDateTime serialisation format in openapi-generator for kotlin client. For http okhttp3 library is used, it's working in a Spring Boot context.

I want to send api requests with ISO_INSTANT format for OffsetDateTime class, instead I have ISO_OFFSET_DATE_TIME format and got error from remote api.

Here is configuration for generator:

openApiGenerate {
    generatorName.set("kotlin")

    inputSpec.set(spec)
    outputDir.set(generatedSourcesDir)

    apiPackage.set("importer.api")
    invokerPackage.set("importer.invoker")
    modelPackage.set("importer.model")

    configOptions.set(mapOf(
        "dateLibrary" to "java8",
        "serializationLibrary" to "jackson",
        "serializableModel" to "true",
        "enumPropertyNaming" to "UPPERCASE",
        "modelMutable" to "true"
    ))
}

The problem here that in generated request classes I cannot annotate fields to specify format. So I tried to specify custom serialiser for my class but was unable to make things work. What is confused me is how retrieving of object mapper implemented in generated code:

package org.openapitools.client.infrastructure

import .....

object Serializer {
    @JvmStatic
    val jacksonObjectMapper: ObjectMapper = jacksonObjectMapper()
        .registerModule(Jdk8Module())
        .registerModule(JavaTimeModule())
        .setSerializationInclusion(JsonInclude.Include.NON_ABSENT)
        .configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false)
}

It's leaving no space to customising object mapper params since it's static method. Most likely I missed smth here, any help would be appreciated.

0 Answers
Related