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/kotlin
bun add @ts-kizuna/kotlin
npm install @ts-kizuna/kotlin
import { generateKotlinClient } from '@ts-kizuna/kotlin';

Parameters

generateKotlinClient(contract: Contract, config: KotlinConfig): string
ParameterTypeDescription
contractContractThe contract from k.contract
configKotlinConfigGeneration configuration

KotlinConfig

OptionTypeRequiredDescription
namespaceNamestringYesName for the generated object and client class (e.g. 'API')
packageNamestringNoPackage declaration for the generated file (e.g. 'com.example.api')
camelCasePropertiesbooleanNoConvert wire field names to camelCase properties, mapped back via @SerialName. Default false
unknownEnumCasebooleanNoEmit 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.

On this page