API Reference
generateKotlinClient
Generate a native Kotlin client from a ts-kizuna contract with OkHttp, kotlinx.serialization, and coroutines.
Generate a native Kotlin client from a contract. The generated client uses OkHttp for HTTP, kotlinx.serialization for JSON, and Kotlin coroutines for async.
pnpm add @ts-kizuna/kotlinbun add @ts-kizuna/kotlinnpm install @ts-kizuna/kotlinimport { generateKotlinClient } from '@ts-kizuna/kotlin';Parameters
generateKotlinClient(contract: Contract, config: KotlinConfig): string| Parameter | Type | Description |
|---|---|---|
contract | Contract | The contract from k.contract |
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 |
Returns
A string containing the generated Kotlin source code.
Example
import path from 'path';
import { writeFileSync } from 'fs';
import { generateKotlinClient } from '@ts-kizuna/kotlin';
import { contract } from '../src/contract';
const kotlin = generateKotlinClient(contract, {
namespaceName: 'API',
packageName: 'com.example.api',
});
writeFileSync('generated/APIClient.kt', kotlin);See the Kotlin client guide for CLI usage and integration patterns.