KtorGenFunction

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class KtorGenFunction(val generate: Boolean = true, val propagateAnnotations: Boolean = true, val annotations: Array<KClass<out Annotation>> = [], val optInAnnotations: Array<KClass<out Annotation>> = [], val customHeader: String = "")

Indicates that a method within a @KtorGen-annotated interface should participate in code generation.

This annotation provides fine-grained control over how annotations from the original interface method are handled and propagated to the generated implementation.

It is useful when you want to selectively propagate certain annotations from the original method, such as @JvmSynthetic, @Deprecated, or annotations marked with @RequiresOptIn, to the generated method.

Example

interface UserRoutes {
@GET("/users/{id}")
@KtorGenFunction(
propagateAnnotations = true, // JvmSynthetic is propagated as-is
annotations = [CustomAnnotation::class], // required have empty constructor, e.g. @JvmOverloads
optInAnnotations = [ExperimentalApi::class], // means = don't propagate, prefer optIn this
)
@JvmSynthetic
@ExperimentalApi
suspend fun getUser(@Path id: Int): User
}

See also

Properties

Link copied to clipboard

KtorGenExperimental Additional annotations or only these annotations to propagate as-is from the interface method to the generated implementation.

Link copied to clipboard

Custom KDoc comment for the generated implementation class.

Link copied to clipboard
val generate: Boolean = true

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

Link copied to clipboard

KtorGenExperimental Opt-in annotations that should be propagated to generated method, 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 method should be copied to the generated method.