Inheritance problem
Ktorfit version
2.0.0-rc01
What happened and how can we reproduce this issue?
I have defined generic interface BaseApi for architecture purposes. Then I created implementation DogApi and define all methods with Ktorfit annotations. Generated implementation class for DogApi tries to also implement BaseApi interface by non-existing _BaseApiImpl class.
BaseApi:
interface BaseApi<KEY, CREATE, UPDATE, DETAIL, LIST> {
suspend fun get(id: KEY): NetworkResult<DETAIL>
suspend fun list(): NetworkResult<List<LIST>>
suspend fun create(dto: CREATE): NetworkResult<DETAIL>
suspend fun update(id: KEY, dto: UPDATE): NetworkResult<DETAIL>
suspend fun delete(id: KEY): NetworkResult<Unit>
}
DogApi:
interface DogApi : BaseApi<
Long,
DogDto.Create,
DogDto.Update,
DogDto.Detail,
DogDto.List> {
@GET("dog/{id}")
override suspend fun get(@Path("id") id: Long): NetworkResult<DogDto.Detail>
@GET("dog")
override suspend fun list(): NetworkResult<List<DogDto.List>>
@POST("dog")
override suspend fun create(@Body dto: DogDto.Create): NetworkResult<DogDto.Detail>
@PUT("dog/{id}")
override suspend fun update(@Path("id") id: Long, @Body dto: DogDto.Update): NetworkResult<DogDto.Detail>
@DELETE("dog/{id}")
override suspend fun delete(@Path("id") id: Long): NetworkResult<Unit>
}
What did you expect to happen?
I am not sure if Ktorfit should also take into account BaseApi interface. Or I would like to somehow forbid this behaviour (maybe some annotation for BaseApi class?). Is there any tool for this in Ktorfit? I couldn't find any.
Is there anything else we need to know about?
I tried to delete delegating from _BaseApiImpl and then everything worked fine.
Wrong generated class header:
public class _DogApiImpl(
private val _ktorfit: Ktorfit,
) : DogApi, BaseApi by com.example.architecture._BaseApiImpl(_ktorfit)
Expected generated class header:
public class _DogApiImpl(
private val _ktorfit: Ktorfit,
) : DogApi {
Thank you for the bug report. I want to fix it, but I'm not sure how easy it will be. I need to think about what happens when there are multiple levels of inheritance
Hi, with Ktorfit 2.2.0 i added this annotation for it: https://foso.github.io/Ktorfit/generation/#nodelegation