Package-level declarations

Core Annotations

This section documents the core annotations used to define options and how the compiler interprets them. These annotations control how Ktorgen scans interfaces, generates client factories, and connects them to Ktor’s HTTP client.

More information, see Core Annotations.

Types

Link copied to clipboard

Each generated class, function, and files is annotated with this to identify them if they need to be excluded, for instance, by static analysis tools.

Link copied to clipboard
@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 customFileHeader: String = KTORGEN_DEFAULT_NAME, val customClassHeader: String = "", val customFileName: String = KTORGEN_DEFAULT_NAME)

Annotation used to generate client implementations for Ktor client interfaces.

Link copied to clipboard
annotation class KtorGenAnnotationPropagation(val propagateAnnotations: Boolean = true, val annotations: Array<KClass<out Annotation>> = [], val optInAnnotations: Array<KClass<out Annotation>> = [], val factoryFunctionAnnotations: Array<KClass<out Annotation>> = [])

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

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class KtorGenCompanionExtFactory(val name: String = "create")

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

Link copied to clipboard

Experimental API, the processor can omit the annotation, or generated code has errors.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class KtorGenFunction(val generate: Boolean = true, val customHeader: String = "")

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

Link copied to clipboard

An annotation used to mark an expect factory function for multi-platform support in KSP running on each platform.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class KtorGenHttpClientExtFactory(val name: String = KTORGEN_DEFAULT_NAME)

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

Link copied to clipboard
expect annotation class KtorGenKmpFactory

An annotation used to mark an expect factory function for multi-platform support in KSP running on each platform.

Link copied to clipboard
@Target(allowedTargets = [AnnotationTarget.CLASS])
annotation class KtorGenTopLevelFactory(val name: String = KTORGEN_DEFAULT_NAME)

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

Link copied to clipboard

Visibility modifier for generated code. Use with @KtorGenVisibilityControl()

Link copied to clipboard
annotation class KtorGenVisibilityControl(val visibilityModifier: KtorGenVisibility = KtorGenVisibility.DEFAULT, val classVisibilityModifier: KtorGenVisibility = KtorGenVisibility.DEFAULT, val constructorVisibilityModifier: KtorGenVisibility = KtorGenVisibility.DEFAULT, val factoryFunctionVisibilityModifier: KtorGenVisibility = KtorGenVisibility.DEFAULT)

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