API Reference
generateSwiftClient
Generate a native Swift client from a ts-kizuna contract with URLSession and Codable.
Generate a native Swift client from a contract. The generated client uses URLSession and Codable, with no third-party Swift dependencies required.
pnpm add @ts-kizuna/swiftbun add @ts-kizuna/swiftnpm install @ts-kizuna/swiftimport { generateSwiftClient } from '@ts-kizuna/swift';Parameters
generateSwiftClient(contract: Contract, config: SwiftConfig): string| Parameter | Type | Description |
|---|---|---|
contract | Contract | The contract from k.contract |
config | SwiftConfig | Generation configuration |
SwiftConfig
| Option | Type | Required | Description |
|---|---|---|---|
namespaceName | string | Yes | Name for the generated Swift enum and client type (e.g. 'API') |
camelCaseProperties | boolean | No | Convert wire field names to camelCase properties, mapped back via CodingKeys. Default false |
unknownEnumCase | boolean | No | Emit enums with an unknown(String) fallback so unrecognised wire values decode instead of throwing. Default false |
Returns
A string containing the generated Swift source code.
Example
import { writeFileSync } from 'node:fs';
import { generateSwiftClient } from '@ts-kizuna/swift';
import { contract } from '../src/contract';
const source = generateSwiftClient(contract, {
namespaceName: 'API',
});
writeFileSync('generated/API.swift', source);See the Swift client guide for CLI usage and integration patterns.