Ktor Gen
Indicates that an interface should be used for Ktor Client code generation.
This annotation controls how the generated class and companion/helper functions are emitted. It is expected to be used on the interface itself or optionally on its companion object for factory generation.
Basic usage:
interface UserRoute {
// Interface definition
// empty definition don't generate code*
@KtorGen
companion object
}
val route: UserRoute
route = _UserRouteImpl(httpClient) // Constructor of impl class
route = UserRoute(httpClient) // Factory top-level function (if enabled)
route = UserRoute.create(httpClient) // Companion factory (if enabled and Companion is available)
route = httpClient.userRoute() // Extension function of HttpClient (if enabled)
The generated implementation will:
Implement the target interface with the same visibility modifier.
Receive an
HttpClient
as its primary constructor argument.Mark all generated code with @Generated and add comments.
See also
Properties
KtorGenExperimental Additional annotations or only these annotations to propagate as-is from the interface to the generated implementation class and extension functions, see more info about functions.
KtorGenExperimental Control the visibility modifier of the generated class only.
KtorGenExperimental Control the visibility modifier of the generated primary constructor only.
Custom KDoc comment or annotations for the generated implementation class.
Custom header comment inserted at the top of the generated Kotlin file.
KtorGenExperimental Additional annotations or only these annotations to propagate as-is to the generated extension functions:
KtorGenExperimental Control the visibility modifier of the generated extension functions only.
Whether to generate a create(client)
extension function of interface's companion object.
Whether to generate an extension function on HttpClient
to instantiate the API.
Whether to generate a top-level function in the same package as the interface.
KtorGenExperimental Opt-in annotations that should be propagated to generated class and extension functions, need be marked with @RequiresOptIn or @SubclassOptInRequired, otherwise the generated code will not compile because requirements of @OptIn.
KtorGenExperimental Indicate if annotations from the source interface should be copied to the generated class and extension functions.
KtorGenExperimental Indicate the visibility modifier for all generated code (class, primary constructor, and extension functions)