KtorGen

@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class KtorGen(val name: String = KTORGEN_DEFAULT_NAME, val generate: Boolean = true, @Language(value = "http-url-reference") val basePath: String = "", val generateTopLevelFunction: Boolean = true, val generateCompanionExtFunction: Boolean = false, val generateHttpClientExtension: Boolean = false, val propagateAnnotations: Boolean = true, val annotations: Array<KClass<out Annotation>> = [], val optInAnnotations: Array<KClass<out Annotation>> = [], val functionAnnotations: Array<KClass<out Annotation>> = [], val visibilityModifier: String = KTORGEN_DEFAULT_NAME, val classVisibilityModifier: String = KTORGEN_DEFAULT_NAME, val constructorVisibilityModifier: String = KTORGEN_DEFAULT_NAME, val functionVisibilityModifier: String = KTORGEN_DEFAULT_NAME, val customFileHeader: String = KTORGEN_DEFAULT_NAME, val customClassHeader: String = "")

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:

See also

Properties

Link copied to clipboard

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.

Link copied to clipboard

Set a base path (or URL) for the current interface, all generated functions going to init with this + it path.

Link copied to clipboard

KtorGenExperimental Control the visibility modifier of the generated class only.

Link copied to clipboard

KtorGenExperimental Control the visibility modifier of the generated primary constructor only.

Link copied to clipboard

Custom KDoc comment or annotations for the generated implementation class.

Link copied to clipboard

Custom header comment inserted at the top of the generated Kotlin file.

Link copied to clipboard

KtorGenExperimental Additional annotations or only these annotations to propagate as-is to the generated extension functions:

Link copied to clipboard

KtorGenExperimental Control the visibility modifier of the generated extension functions only.

Link copied to clipboard
val generate: Boolean = true

Indicate the annotated interface going to generate the code or not.

Link copied to clipboard

Whether to generate a create(client) extension function of interface's companion object.

Link copied to clipboard

Whether to generate an extension function on HttpClient to instantiate the API.

Link copied to clipboard

Whether to generate a top-level function in the same package as the interface.

Link copied to clipboard

Custom name for the generated implementation class.

Link copied to clipboard

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.

Link copied to clipboard

KtorGenExperimental Indicate if annotations from the source interface should be copied to the generated class and extension functions.

Link copied to clipboard

KtorGenExperimental Indicate the visibility modifier for all generated code (class, primary constructor, and extension functions)