OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.23k stars 6.43k forks source link

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

Open ivanvasheka-intellias opened 1 year ago

ivanvasheka-intellias commented 1 year ago
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

kotovdv commented 4 months ago

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

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

ivanvasheka-intellias commented 4 months ago

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