API Reference
Kizuna.model
Give a Zod schema a name so OpenAPI and Swift generators produce named types instead of inline definitions.
Give a Zod schema a name so generators produce named types instead of inline definitions.
pnpm add @ts-kizuna/corebun add @ts-kizuna/corenpm install @ts-kizuna/coreimport { Kizuna } from '@ts-kizuna/core';Parameters
Kizuna.model accepts a single options object:
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. Use it exactly like any other Zod schema in your routes.
Example
import { Kizuna } from '@ts-kizuna/core';
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
Without a title, generators inline the schema everywhere it appears. With Kizuna.model:
- OpenAPI: the schema is extracted into
components.schemas.Userand every usage becomes a$refreference - Swift: the schema becomes a named
public struct Userin the generated client, 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 Contract guide for more details.