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

Parameters

Kizuna.model accepts a single options object:

Kizuna.model(options: ModelOptions): ZodType
OptionTypeRequiredDescription
titlestringYesThe name used in generated output (User, Event, etc.)
descriptionstringNoDescription included in the OpenAPI spec
schemaZodTypeYesThe 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.User and every usage becomes a $ref reference
  • Swift: the schema becomes a named public struct User in 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.

On this page