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 customFileHeader: String = KTORGEN_DEFAULT_NAME, val customClassHeader: String = "", val customFileName: String = KTORGEN_DEFAULT_NAME)(source)

Annotation used to generate client implementations for Ktor client interfaces.

This annotation is typically used to mark interfaces intended to define API contracts, enabling automatic generation of client-side code based on the provided configuration.

The annotation provides customization options such as specifying a custom implementation class name, controlling generation behavior, defining base paths, adding custom file and class headers, and more.

By default, the generated implementation will have:

  • Named as the interface name plus the suffix Impl.

  • A class with the same visibility as the interface.

  • A constructor with a single HttpClient parameter + properties + delegated if are defined in the interface.

See also

Properties

Link copied to clipboard

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

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

Custom file name for the generated implementation class.

Link copied to clipboard
val generate: Boolean = true

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

Link copied to clipboard

Custom name for the generated implementation class.