Skip to content

Draft: TypeWrapper API compatibility protection

Ivan “CLOVIS” Canet requested to merge api-compatibility into main

Currently (dd39da37), the project has the downside that the Endpoint type has multiple type parameters. It is likely that we will want to add new type parameters in the future. Adding type parameters is a binary-compatible change. However, if the user has explicitly written Endpoint<T1, T2, T3> anywhere, that code will stop compiling.

In the prototype, this has been considered an acceptable downside, since Kotlin's type inference makes specifying the type optional:

object Users : StaticResource("users") {
    val list by get()
        .response<List<UserDto>>()
}

In that example, list had type Endpoint<Unit, List<UserDto>, Parameters.Empty>. However, since the type was not written explicitly, it would not break when more type parameters would be added.

This MR is an attempt at forbidding the user from writing the type at all. The type information is moved to a hidden class TypeWrapper that users cannot write down thanks to DeprecationLevel trickery. This solution was in great part inspired by Youssef Shoaib in the Kotlin Slack.

Merge request reports