kfx

Generate code from supported API formats.

kfx parses API files, transforms them into an intermediate representation (IR) and uses a code generator to actually create the code by consuming the IR.

kfx supports some API formats and code generators out of the box, but due to its plugin mechanisms it's easy to support other api formats or code generators too.

What's included

API formats:

  • WSDL (including XSD)

  • Swagger

  • OpenAPI

Code generators:

  • Kotlin classes using Kotlinx.serialization

  • Ktor client functions

  • Ktor server functions

Gradle plugin

plugins {
id("io.github.hfhbd.kfx") version "LATEST"
}

kfx {
register("myApi", OpenApi::class) {
files.from(file("myApi.json"))
dependencies {
compiler(kotlin())
compiler(kotlinxJson())
compiler(ktorClient())
}
sourceSets.main {
usingSourceSet(kotlin)
}
}
}

To generate code, you need to call register/create and configure the compilation. In the dependencies block, you define what code should be generated:

  • kotlin: Kotlin classes only

  • kotlinxJson: Adds @Serializable annotation to Kotlin classes

  • ktorClient: Generates ktor client functions

  • ktorServer: Generates ktor server Route functions

You also need to call usingSourceSet to connect the generated code to a Gradle SourceSet.

Custom Transformer

Often, api files need some transformation, to change the Kotlin type, to add some documentation or custom types, or just to fix some wrong apis until a new version will be released.

There are three kind of transformers, format specific ones, IR transformers and code gen transformers. The transformers are loaded using JVM ServiceLoader mechanism and needs to be added to the format dependency configuration.

All modules:

Link copied to clipboard
Link copied to clipboard

This module transforms the wsdl to IR, which will be used by a CodeGenerator to generate actual classes.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

This module creates the CodegenTree from the IRTree.

Link copied to clipboard

Integrates the WSDL generator with a Kotlin JVM and Kotlin Multiplatform project.

Link copied to clipboard

This module adds OData transformation support.

Link copied to clipboard

This module adds the package name to all IR classes if there is no package name yet.

Link copied to clipboard

This module removes the suffix Type of a variable name, if possible.

Link copied to clipboard

This module generates the Kotlin base classes.

Link copied to clipboard

This module contains helper methods for Kotlin based generators using kotlinpoet.

Link copied to clipboard

This module generates the Ktor client functions.

Link copied to clipboard

This module generates the Ktor server functions.

Link copied to clipboard

This module generates the Ktor client functions.

Link copied to clipboard

Runtime artifact containing the soap action Routing.

Link copied to clipboard

This module contains util functions shared between ktor-client and ktor-server.

Link copied to clipboard

Runtime artifact containing the OAuth2Token serializable class.

Link copied to clipboard
Link copied to clipboard

This module contains the data model to read a openAPI file.

Link copied to clipboard

This module adds the SOAP io.github.hfhbd.kfx.soap.Envelope wrapper to each operation.

Link copied to clipboard

Runtime artifact containing the soap.Envelope serializable class.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

This module adds app.softwork.validation support.

Link copied to clipboard
Link copied to clipboard

This module contains the data model to read a wsdl file.