Skip to content

RawToast/zenko

Repository files navigation

Zenko

CI codecov

Bun-first TypeScript generator for OpenAPI specifications that creates Zod schemas, type-safe path functions, and operation objects.

Unlike most OpenAPI generators, Zenko does not create a client. Instead you are free to use your own fetch/undici wrapper or library of choice.

Quick Start

# One-time usage (no installation required)
bunx zenko input.yaml output.ts
# Or install globally
bun install -g zenko
zenko input.yaml output.ts
# Or as a script in your package.json
bun add -d zenko

# Then in your package.json, note the `-b` flag to run the command with Bun and not Node.
"scripts": {
  "generate": "bun -b zenko --config resources/zenko.config.json"
}

Features

  • 🔧 Zod Schema Generation - Runtime-validated schemas from OpenAPI
  • 🛣️ Type-safe Path Functions - Build API paths with proper TypeScript types
  • 📋 Operation Objects - Path functions, request validation, and response types
  • 🧰 Operation Type Helpers - Reusable type definitions for building generic clients
  • 🔄 Dependency Resolution - Automatic topological sorting eliminates "used before declaration" errors
  • 🔓 Open Enums - Accept unknown enum values gracefully with configurable prefixes
  • CLI & Programmatic API - Use via command line or import as a library

Basic Usage

Command Line

# Generate from OpenAPI spec
zenko petstore.yaml api-types.ts

# Enable strict validation
zenko api.yaml types.ts --strict-dates --strict-numeric

# Use config file for multiple specs
zenko --config zenko.config.json

Config File

{
  "$schema": "https://raw.githubusercontent.com/RawToast/zenko/refs/heads/master/packages/zenko/zenko-config.schema.json",
  "schemas": [
    {
      "input": "api.yaml",
      "output": "api.gen.ts"
    }
  ]
}

Using Generated Code

import { paths, authenticateUser } from "./api.gen"

// Type-safe path building
const path = paths.getUserById({ userId: "123" })
// → "/users/123"

// Request validation with Zod
const validation = authenticateUser.request(requestData)
if (validation.success) {
  const response = await fetch(baseUrl + authenticateUser.path(), {
    method: "POST",
    body: JSON.stringify(validation.data),
  })
}

Documentation

Requirements

  • Bun 1.2.22 or higher

An npm package may be available in the future if there is demand.

About

TypeScript generator for OpenAPI schemas using Zod for type-safe helper functions

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •