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@beta
bun add kizunajs@beta
npm install kizunajs@beta
import { Kizuna } from 'kizunajs';

Parameters

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, usable anywhere a Zod schema is.

Example

users.ts
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.User and every usage becomes a $ref reference
  • Swift: an object becomes public struct User, a z.enum becomes public enum EventKind, shared across all routes that reference it
  • Kotlin: an object becomes @Serializable data class User, a z.enum becomes enum class EventKind, shared across all routes that reference it

Extracting TypeScript types

Export a type alongside the schema with z.infer:

types.ts
export type User = z.infer<typeof UserSchema>;

See the Routes guide for more details.

On this page