openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][KOTLIN] When generating apis and modals only using retrofit2 api files contain invalid import

Open ivanvasheka-intellias opened this issue 2 years ago • 2 comments

Description

When generating code using kotlin generator with options to generate APIs and models files only, and using retrofit2 library, generator generates API files without infrastructure package, but API files contain imports of infrastructure classes which results into an error. In particular this one:

import com.example.api.infrastructure.CollectionFormats.*

openapi-generator version

6.3.0

OpenAPI declaration file content or url

task generateApi(type: GenerateTask) { generateApi.generatorName = "kotlin" generateApi.packageName = "com.example.api" generateApi.inputSpec = "api.json" generateApi.outputDir = "$rootDir/api" generateApi.skipValidateSpec = true

generateApi.additionalProperties = [
        useCoroutines: "true",
        library      : "jvm-retrofit2",
        sourceFolder : "src/main/java",
]
generateApi.globalProperties = [
        apiDocs  : "false",
        modelDocs: "false",
        apis     : "",
        models   : "",
]

}

Steps to reproduce

generate API files using provided options open any API file check imports

ivanvasheka-intellias avatar Apr 03 '23 11:04 ivanvasheka-intellias

@ivanvasheka-intellias did you find a workaround for this?

I am having the very same issue, but java + retrofit2 code generation options

kotovdv avatar Apr 23 '24 11:04 kotovdv

@ivanvasheka-intellias did you find a workaround for this?

I am having the very same issue, but java + retrofit2 code generation options

Yes. So the workaround for me was to allow generator to generate that exact file by adding this to the configuration:

task.globalProperties = [
    supportingFiles: "CollectionFormats.kt"
]

With this setting that file is generated and the import is valid despite the file not being used anywhere...

ivanvasheka-intellias avatar Apr 23 '24 11:04 ivanvasheka-intellias