Error generating code with openapi-generator kotlin-server

47 views Asked by At

I am developing an API using Ktor and Kotlin. And I want to generate the models and interfaces from the swagger, but I am getting an error when generating the files. It seems that the "interfaceOnly" config is not working. The file "/build/generated/src/main/kotlin/org/openapitools/server/AppMain.kt" is being generated missing a "}" at the end of the file. In the Paths file it is asking to use a serializer but I did not see a parameter in the openapi-generator settings to do this.

I opened an issue in the openapi-generator repository describing the problem better https://github.com/OpenAPITools/openapi-generator/issues/18162

openApiGenerate {
    generatorName.set("kotlin-server")
    inputSpec.set("$rootDir/src/main/resources/swagger.yaml")
    outputDir.set(generatedSourcesPath)
    generateApiTests.set(false)
    generateModelTests.set(false)
    configOptions.set(
        mapOf(
            "interfaceOnly" to "true",
            "serializationLibrary" to "kotlinx.serialization.json.JsonObject",
            "additionalModelTypeAnnotations" to "@Contextual"
        )
    )
}

kotlin.sourceSets["main"].kotlin.srcDir("$generatedSourcesPath/src/main/kotlin")

tasks.withType<KotlinCompile>().configureEach {
    dependsOn("openApiGenerate")
}

error descrition

I tried to modify openApiGenerate's "configOptions" in several ways to generate only the interfaces and models but nothing worked.

0

There are 0 answers