vika-cli 1.1.0

Generate TypeScript types, Zod schemas, and Fetch-based API clients from OpenAPI/Swagger specifications
Documentation

๐Ÿš€ vika-cli

A blazing-fast Rust-powered OpenAPI code generator that produces TypeScript types, Zod schemas, and Fetch clients โ€” designed for real-world DX.

CI License: MIT

vika-cli is a blazing-fast, production-grade code generator that transforms any Swagger/OpenAPI specification into fully typed:

  • TypeScript interfaces
  • Zod validation schemas
  • Fetch-based API client functions
  • Module-organized output structure

Built in Rust for exceptional performance and reliability.


โœจ Features

  • ๐Ÿš€ Ultra-fast Rust engine with deep schema resolution
  • ๐Ÿ“ฆ Module-based generation (grouped by Swagger tags)
  • ๐Ÿงฌ TypeScript interfaces from OpenAPI schemas
  • ๐Ÿ›ก๏ธ Zod validation schemas with constraints
  • ๐Ÿ”Œ Strongly-typed Fetch API client generation
  • ๐ŸŽฏ Interactive module selection
  • ๐ŸŽ› Config-driven outputs (.vika.json)
  • ๐Ÿ’พ Spec caching for fast regeneration
  • ๐Ÿ”„ Backup system for generated files
  • โš ๏ธ Conflict detection for user-modified files
  • ๐Ÿ” Inspect command for analyzing specs
  • ๐ŸŽจ Progress indicators and verbose logging
  • ๐Ÿง  Handles: oneOf, anyOf, allOf, enums, recursion, circular refs
  • ๐ŸŒ Supports HEAD, OPTIONS, PATCH, all HTTP verbs
  • ๐Ÿ›  Multi-platform installers + CI/CD automation

โš–๏ธ Comparison With Other Tools

Tool Types Zod Client Rust Speed Module Selection Inspect Cache
vika-cli โœ… โœ… Fetch โšกโšกโšก โœ… โœ… โœ…
openapi-typescript โœ… โŒ โŒ โŒ โŒ โŒ โŒ
Orval โš ๏ธ โš ๏ธ Axios/Fetch โŒ โŒ โŒ โŒ
openapi-client-axios โŒ โŒ Axios โŒ โŒ โŒ โŒ

Why choose vika-cli?

  • ๐Ÿš€ Rust-powered: Blazing fast schema resolution and code generation
  • ๐Ÿ›ก๏ธ Complete validation: Native Zod schema generation with full constraint support
  • ๐Ÿ“ฆ Modular: Interactive module selection for selective generation
  • ๐Ÿ” Built-in inspection: Analyze specs without generating code
  • ๐Ÿ’พ Smart caching: Fast regeneration with intelligent spec caching
  • ๐ŸŽฏ Developer experience: Conflict detection, backups, and progress indicators

๐Ÿ“ฆ Installation

macOS & Linux (recommended)

curl -fsSL https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.sh | sh

Windows (PowerShell)

irm https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.ps1 | iex

Cargo

cargo install vika-cli

From Source

git clone https://github.com/MahdiZarrinkolah/vika-cli
cd vika-cli
cargo build --release

๐Ÿš€ Quick Start

1๏ธ Initialize a project

vika-cli init

Creates a .vika.json configuration file.

2๏ธ Generate code from an OpenAPI specification

Remote:

vika-cli generate --spec https://example.com/openapi.json

Local:

vika-cli generate --spec ./swagger.yaml

Flags:

Flag Description
--verbose Show detailed output
--cache Use cached version of the spec
--backup Backup files before overwriting
--force Force overwrite conflicts

The generator will:

  1. Parse the spec
  2. Extract modules (tags)
  3. Ask you which modules to generate
  4. Produce TypeScript + Zod + Fetch clients
  5. Show a detailed generation summary table

3๏ธ Update previously generated modules

vika-cli update

4๏ธ Inspect a specification (no generation)

vika-cli inspect --spec ./swagger.yaml

Examples:

vika-cli inspect --spec ./swagger.yaml --module products
vika-cli inspect --spec ./swagger.yaml --schemas
vika-cli inspect --spec ./swagger.yaml --json

๐Ÿง  How It Works

vika-cli uses a robust generation pipeline:

1. Spec Parsing

Reads OpenAPI 3.x JSON/YAML.

2. Module Extraction

Groups endpoints by Swagger tags.

3. Schema Resolution

Resolves:

  • $ref
  • Circular dependencies
  • Recursive models
  • oneOf / anyOf / allOf
  • Enum values
  • Nullable fields

4. Code Generation

Produces:

  • TypeScript interfaces
  • Zod schemas with constraints
  • Fetch-based API clients

5. Safe Writing

  • Writes only changed files
  • Detects conflicts
  • Optional backup mode
  • Generates index/barrel files
  • Optional Prettier/Biome post-formatting

โš™๏ธ Configuration (.vika.json)

{
  "rootDir": "src",
  "schemas": {
    "output": "src/schemas",
    "naming": "PascalCase"
  },
  "apis": {
    "output": "src/apis",
    "style": "fetch",
    "baseUrl": "/api/v1",
    "headerStrategy": "bearerToken"
  },
  "modules": {
    "ignore": ["Auth"]
  }
}

Configuration Options

Key Description
schemas.output Directory for types + Zod schemas
schemas.naming Naming convention for generated types
apis.output Directory for API clients
apis.baseUrl Base URL prefix for client requests
apis.headerStrategy bearerToken, fixed, consumerInjected
modules.ignore Skip tagged modules

Full reference: docs/configuration.md


๐Ÿงฑ Output Structure

๐Ÿ“ src/
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ schemas/
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ products/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ types.ts          # TypeScript interfaces
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ schemas.ts        # Zod validation schemas
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ index.ts          # Barrel exports
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ ๐Ÿ“ users/
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ types.ts
โ”‚   โ”‚   โ”œโ”€โ”€ ๐Ÿ“„ schemas.ts
โ”‚   โ”‚   โ””โ”€โ”€ ๐Ÿ“„ index.ts
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ ๐Ÿ“ orders/
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ types.ts
โ”‚       โ”œโ”€โ”€ ๐Ÿ“„ schemas.ts
โ”‚       โ””โ”€โ”€ ๐Ÿ“„ index.ts
โ”‚
โ””โ”€โ”€ ๐Ÿ“ apis/
    โ”‚
    โ”œโ”€โ”€ ๐Ÿ“„ http.ts                # HTTP client utility
    โ”‚
    โ”œโ”€โ”€ ๐Ÿ“ products/
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ index.ts           # API client functions
    โ”‚
    โ”œโ”€โ”€ ๐Ÿ“ users/
    โ”‚   โ””โ”€โ”€ ๐Ÿ“„ index.ts
    โ”‚
    โ””โ”€โ”€ ๐Ÿ“ orders/
        โ””โ”€โ”€ ๐Ÿ“„ index.ts

File types:

  • ๐ŸŸฆ types.ts - TypeScript type definitions (ProductDto, UserProfile, etc.)
  • ๐ŸŸจ schemas.ts - Zod validation schemas (ProductDtoSchema, etc.)
  • ๐ŸŸฉ index.ts - Barrel exports and API client functions
  • ๐ŸŸง http.ts - Core HTTP client with fetch wrapper

๐Ÿ“˜ Example Output

TypeScript Types

export interface ProductDto {
  id: string;
  price: number;
  title: string;
}

Zod Schema

export const ProductDtoSchema = z.object({
  id: z.string(),
  price: z.number(),
  title: z.string(),
});

Fetch API Client

export const getProduct = async (id: string): Promise<ProductDto> =>
  http.get(`/products/${id}`);

๐Ÿงฉ Advanced Features

โšก Caching

vika-cli generate --cache

๐Ÿ›ก Backup Mode

vika-cli generate --backup

Backups stored in:

.vika-backup/<timestamp>/

โš  Conflict Detection

Warns if manually modified files would be overwritten.

๐Ÿงช Snapshot Testing

Using insta for generator correctness.


๐Ÿงฑ Architecture Overview

  • Commands: init, generate, update, inspect
  • Generator Core: TS/Zod/API client generation
  • Schema Resolver: Handles refs, unions, recursion
  • Writer System: Diffs, backups, conflict detection
  • Config System: Load & validate .vika.json
  • Error System: Structured typed errors
  • Utilities: caching, formatting, progress indicators

Details: docs/architecture.md


๐Ÿ”„ Development & Release

CI includes:

  • cargo fmt
  • cargo clippy
  • Unit tests
  • Snapshot tests
  • Multi-platform builds

Releases

cargo release patch

Semantic versioning applies:

  • MAJOR = breaking changes
  • MINOR = new features
  • PATCH = fixes

See: CHANGELOG.md


๐Ÿค Contributing

  1. Fork
  2. Create a feature branch
  3. Make changes with tests
  4. Submit a PR

Guide: docs/contributing.md


๐Ÿ“œ License

MIT


๐Ÿ”— Links


๐ŸŽ‰ Thank You

vika-cli is now a fully production-grade OpenAPI codegen tool.

Enjoy building! ๐Ÿš€