Skip to content

Generic type defined in a different module #939

@dshatz

Description

@dshatz

Ktorfit version

2.6.4

What happened and how can we reproduce this issue?

A class like this is defined in module A.

@Serializable
data class Request<T>(
    val data: T,
    @SerialName("metainfo") val metaInfo: MetaInfoModel
)

@Serializable
data class ResponseModel<T>(val data: ErrorsAndData<T>, ...)

In module B I have a Ktorfit service:

interface Service {
    @POST("url")
    suspend fun getData(@Body body: Request<String>): ResponseModel<Int>

What did you expect to happen?

Should work fine

Is there anything else we need to know about?

The following is generated:

override suspend fun getData(body: Request): ResponseModel {
    val _ext: HttpRequestBuilder.() -> Unit = {
        this.method = HttpMethod.parse("POST")
        url{
        takeFrom(_ktorfit.baseUrl + "url")
        }
        setBody(body) 
        }
    val _typeData = TypeData.createTypeData(
    typeInfo = typeInfo<ResponseModel>(),
    )
    return _helper.suspendRequest(_typeData,_ext)!!
  }

Notice the lack of Request and Response generic type parameters. Obviously this doesn't compile.

ksp = "2.2.21-2.0.4"
kotlin = "2.2.21"

K2 mode

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions