API Reference
Kizuna.model
Give a Zod schema a name so the OpenAPI, Swift and Kotlin generators produce named types instead of inline definitions.
Give a Zod schema a name, so OpenAPI and the Swift and Kotlin generators emit a named type for it.
pnpm add kizunajs@betabun add kizunajs@betanpm install kizunajs@betaimport { Kizuna } from 'kizunajs';Parameters
Kizuna.model(options: ModelOptions): ZodType| Option | Type | Required | Description |
|---|---|---|---|
title | string | Yes | The name used in generated output (User, Event, etc.) |
description | string | No | Description included in the OpenAPI spec |
schema | ZodType | Yes | The Zod schema defining the shape and validation |
Returns
The Zod schema with metadata attached, usable anywhere a Zod schema is.
Example
import { Kizuna } from 'kizunajs';
import { z } from 'zod';
export const UserSchema = Kizuna.model({
title: 'User',
description: 'A user in the system',
schema: z.object({
id: z.string(),
name: z.string(),
email: z.email(),
}),
});Effect on generators
With Kizuna.model:
- OpenAPI: the schema is extracted into
components.schemas.Userand every usage becomes a$refreference - Swift: an object becomes
public struct User, az.enumbecomespublic enum EventKind, shared across all routes that reference it - Kotlin: an object becomes
@Serializable data class User, az.enumbecomesenum class EventKind, shared across all routes that reference it
Extracting TypeScript types
Export a type alongside the schema with z.infer:
export type User = z.infer<typeof UserSchema>;See the Routes guide for more details.