API Reference
generateKotlinClient
Generate a native Kotlin client from a Kizuna API with OkHttp, kotlinx.serialization, and coroutines.
Beta
The Kotlin client is new and still settling. The generated API surface may change while v2 is in beta, so pin your version if you depend on it.
Generate a native Kotlin client from your routes. The generated client uses OkHttp for HTTP, kotlinx.serialization for JSON, and Kotlin coroutines for async.
pnpm add @kizunajs/kotlin@betabun add @kizunajs/kotlin@betanpm install @kizunajs/kotlin@betaimport { generateKotlinClient } from '@kizunajs/kotlin';Parameters
generateKotlinClient(api: ApiDefinition, config: KotlinConfig): string| Parameter | Type | Description |
|---|---|---|
api | ApiDefinition | The api from defineConfig |
config | KotlinConfig | Generation configuration |
KotlinConfig
| Option | Type | Required | Description |
|---|---|---|---|
namespaceName | string | Yes | Name for the generated object and client class (e.g. 'API') |
packageName | string | No | Package declaration for the generated file (e.g. 'com.example.api') |
camelCaseProperties | boolean | No | Convert wire field names to camelCase properties, mapped back via @SerialName. Default false |
unknownEnumCase | boolean | No | Emit enums as a sealed interface with an Unknown(wireValue) member so unrecognised wire values decode instead of throwing. Default false |
Example
import path from 'path';
import { writeFileSync } from 'fs';
import { generateKotlinClient } from '@kizunajs/kotlin';
import kizuna from '../kizuna.config';
const kotlin = generateKotlinClient(kizuna.api, {
namespaceName: 'API',
packageName: 'com.example.api',
});
writeFileSync('generated/APIClient.kt', kotlin);See the Kotlin client guide for CLI usage and integration patterns.