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.81k stars 6.58k forks source link

[BUG] Kotlin generator Import Mappings Not working as expected #5632

Open ghost opened 4 years ago

ghost commented 4 years ago
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

ghost commented 4 years ago

I bumped the version to 4.3.0 and used jackson as the serialization library and get the same behaviour still.

rahul6941 commented 2 years ago

Any solution for this one ? Facing same problem