A powerful Gradle plugin that transforms OpenAPI v3 specifications into production-ready Kotlin Ktor client code. You can customize the generated clients and models to match your project's specific needs.
- JDK 17+
- Gradle 9+
Add the plugin to your build.gradle.kts:
plugins {
id("org.litote.openapi.ktor.client.generator.gradle") version "<last version>"
}Configure the plugin in your build.gradle.kts:
apiClientGenerator {
generators {
create("openapi") { // Task name: generateOpenapi
outputDirectory = file("build/generated")
openApiFile = file("src/main/openapi/openapi.json")
basePackage = "com.example.api"
// Optional: Add more configuration options below
}
// You can create multiple generators with different names
}
}For a complete example with all available options, see e2e/build.gradle.kts.
Run the generation task directly:
./gradlew generateOpenapiOr trigger generation as part of the build process:
./gradlew buildThis will generate Ktor client code based on your OpenAPI specification and plugin configuration. The generated code will be placed in the configured outputDirectory.
| Property | Description | Default value | Allowed values |
|---|---|---|---|
generators |
Generators configuration | {} |
Any configuration |
skip |
Skip all clients generation | false | Boolean |
| Property | Description | Default value | Allowed values |
|---|---|---|---|
openApiFile |
OpenAPI v3 source file | file("src/main/openapi/${name}.json") |
Any existing OpenAPI file |
outputDirectory |
Target directory for generated sources (a src/main/kotlin subdirectory will be added) |
file("build/api-${name}") |
Any relative directory |
basePackage |
Base package for all generated classes | org.example |
Any valid package name |
allowedPaths |
Restrict generation to a subset of OpenAPI paths | empty (all paths are generated) | Any subset of paths defined in the OpenAPI spec |
modulesIds |
Extra generation modules to enable | Empty (no modules) | UnknownEnumValueModule, LoggingSl4jModule |
skip |
Skip this client generation | false | Boolean |
generator/- Core code generation logic and OpenAPI parsinggradle-plugin/- Gradle plugin implementation and task integratione2e/- End-to-end test project(s) with example configurationsmodule/- Optional modules for extended functionalityshared/- Shared utilities and code used across modules