OpenAPITools / OpenAPITools/openapi-generator
[BUG] Kotlin generator Import Mappings Not working as expected
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I’m using the Maven plugin (version 4.2.3) to generate Kotlin DTOs.
I’m having trouble with the Import Mappings. If I change the generators name to Java then the import mappings happen as I expect but with Kotlin I experience weird behaviour.
Here is my config:
<configuration>
<inputSpec>
${sourceDirectory}/definitions/api_common_1.0.yml
</inputSpec>
<output>${sourceDirectory}</output>
<generatorName>kotlin</generatorName>
<modelPackage>com.example.infrastructure.adapters.foo.dto</modelPackage>
<configOptions>
<useBeanValidation>true</useBeanValidation>
<dateLibrary>java8</dateLibrary>
<hideGenerationTimestamp>true</hideGenerationTimestamp>
<serializationLibrary>gson</serializationLibrary>
</configOptions>
<generateApis>false</generateApis>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelDocumentation>false</generateModelDocumentation>
<generateModels>true</generateModels>
<generateSupportingFiles>false</generateSupportingFiles>
<skipValidateSpec>true</skipValidateSpec>
<importMappings>
Status=com.example.infrastructure.adapters.foo.dto.common.v1.Status
</importMappings>
</configuration>
And here is the Kotlin code that are generated, look at the import of Status:
package com.example.infrastructure.adapters.foo.dto
import com.example.infrastructure.adapters.foo.dto.com.example.infrastructure.adapters.foo.dto.common.v1.Status
import com.google.gson.annotations.SerializedName
/**
*
* @param header
*/
data class Response (
@SerializedName("status")
val status: com.example.infrastructure.adapters.foo.dto.common.v1.Status? = null
)
The expected output is:
package com.example.infrastructure.adapters.foo.dto
import com.google.gson.annotations.SerializedName
/**
*
* @param header
*/
data class Response (
@SerializedName("status")
val status: com.example.infrastructure.adapters.foo.dto.common.v1.Status? = null
)
openapi-generator version
4.2.3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Kotlin generator's handling of the supplied importMappings configuration and compare it with the Java generator behavior described in the issue. Reproduce the Maven plugin 4.2.3 configuration, then verify that the generated Kotlin file imports Status without duplicating the model package prefix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100