๐ vika-cli
A blazing-fast Rust-powered OpenAPI code generator that produces TypeScript types, Zod schemas, and Fetch clients โ designed for real-world DX.
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
- ๐จ Customizable templates (Tera-based) with user overrides
- ๐ Multi-platform installers + CI/CD automation
- ๐ Multi-spec support for microservices architectures
โ๏ธ 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)
|
Windows (PowerShell)
irm https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.ps1 | iex
Cargo
From Source
๐ Quick Start
1๏ธ Initialize a project
init now captures your first spec (name, path, schema/api outputs, module preferences) and writes .vika.json.
Need more specs later? Run vika-cli add each time you want to register another service.
2๏ธ Generate code from your configured specs
# Interactive selection (default)
# Force a specific spec
# Regenerate everything
Generation always uses the specs defined in .vika.json; the CLI no longer accepts raw spec paths. Remote URLs and local files are supported via each specโs path.
Flags:
| Flag | Description |
|---|---|
--spec <name> |
Generate specific spec (single or multi-spec mode) |
--all-specs |
Generate all specs (multi-spec mode only) |
--verbose |
Show detailed output |
--cache |
Use cached version of the spec |
--backup |
Backup files before overwriting |
--force |
Force overwrite conflicts |
The generator will:
- Parse the spec(s)
- Extract modules (tags)
- Ask you which modules to generate
- Produce TypeScript + Zod + Fetch clients
- Show a detailed generation summary table
3๏ธ Update previously generated modules
4๏ธ Inspect a specification (no generation)
Single Spec Mode
Multi-Spec Mode
# Inspect all specs
# Inspect specific spec by name
Examples:
# Single spec mode
# Multi-spec mode
๐ง 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)
vika-cli now uses a single, always-multi-spec configuration model. Every spec lives inside the specs array and declares its own schema/API/module configuration.
Global settings
| Key | Description |
|---|---|
root_dir |
Base directory for generated files (src by default). |
generation.enable_cache |
Cache parsed specs for faster re-runs (default true). |
generation.enable_backup |
Create timestamped backups before overwriting (default false). |
generation.conflict_strategy |
How to handle modified files: ask, force, or skip. |
Spec entry reference
| Key | Description |
|---|---|
specs[].name |
Unique spec identifier (kebab-case recommended). |
specs[].path |
Local file path or URL to the OpenAPI document. |
specs[].schemas.output |
Destination folder for TypeScript + Zod output for this spec. |
specs[].schemas.naming |
Naming convention (PascalCase, camelCase, snake_case, kebab-case). |
specs[].apis.output |
Output folder for this specโs API clients. |
specs[].apis.style |
Client style. Currently only fetch. |
specs[].apis.base_url |
Optional base URL baked into generated clients. |
specs[].apis.header_strategy |
consumerInjected, bearerToken, or fixed. |
specs[].modules.ignore |
Tags to skip entirely. |
specs[].modules.selected |
Tags to generate. Filled automatically after the first run or when using interactive prompts. |
Add new specs via vika-cli add (appends to specs). vika-cli init only creates the first entry, keeping multi-spec workflows predictable.
Full reference: docs/configuration.md
๐จ Customizing Templates
vika-cli uses Tera templates for code generation. You can customize the output format by overriding built-in templates.
Quick Start
-
Initialize templates (copies built-in templates to
.vika/templates/): -
List available templates:
-
Customize templates in
.vika/templates/:# Edit .vika/templates/type-interface.tera # Edit .vika/templates/api-client-fetch.tera # etc. -
Regenerate code - your custom templates will be used automatically:
Template Files
type-interface.tera- TypeScript interface generationtype-enum.tera- TypeScript enum generationzod-schema.tera- Zod schema generationapi-client-fetch.tera- API client function generation
Template Resolution: User templates in .vika/templates/ override built-in templates automatically.
Full documentation: docs/templates.md
๐งฑ Output Structure
Single Spec Mode
๐ 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/
โ
โโโ ๐ runtime/ # Runtime HTTP client with ApiResult types
โ โโโ ๐ types.ts # ApiResult type definitions
โ โโโ ๐ http-client.ts # VikaClient class with middleware, retries, auth
โ โโโ ๐ index.ts # Runtime exports
โ
โโโ ๐ products/
โ โโโ ๐ index.ts # API client functions
โ
โโโ ๐ users/
โ โโโ ๐ index.ts
โ
โโโ ๐ orders/
โโโ ๐ index.ts
Multi-Spec Mode (Microservices)
When using specs array, output is organized by spec name:
๐ src/
โ
โโโ ๐ schemas/
โ โ
โ โโโ ๐ ecommerce/ # From ecommerce spec
โ โ โโโ ๐ products/
โ โ โ โโโ ๐ types.ts
โ โ โ โโโ ๐ schemas.ts
โ โ โ โโโ ๐ index.ts
โ โ โโโ ๐ orders/
โ โ โโโ ...
โ โ
โ โโโ ๐ admin/ # From admin spec
โ โ โโโ ๐ users/
โ โ โโโ ๐ permissions/
โ โ
โ โโโ ๐ public/ # From public spec
โ โโโ ๐ catalog/
โ
โโโ ๐ apis/
โ
โโโ ๐ runtime/ # Runtime HTTP client with ApiResult types
โ โโโ ๐ types.ts # ApiResult type definitions
โ โโโ ๐ http-client.ts # VikaClient class with middleware, retries, auth
โ โโโ ๐ index.ts # Runtime exports
โ
โโโ ๐ ecommerce/ # From ecommerce spec
โ โโโ ๐ products/
โ โ โโโ ๐ index.ts
โ โโโ ๐ orders/
โ โโโ ๐ index.ts
โ
โโโ ๐ admin/ # From admin spec
โ โโโ ๐ users/
โ โโโ ๐ index.ts
โ
โโโ ๐ public/ # From public spec
โโโ ๐ catalog/
โโโ ๐ index.ts
This structure ensures:
- โ Isolation: Each spec's generated code is separated
- โ No conflicts: Different specs can have modules with the same name
- โ Clear organization: Easy to identify which service generated which code
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
Multi-Spec Support (Microservices)
vika-cli supports generating code from multiple OpenAPI specifications in a single project. This is ideal for microservices architectures where different services expose separate APIs.
Benefits
- ๐ Multiple Services: Generate code for all your microservices in one command
- ๐ฆ Isolated Output: Each spec's code is organized in separate directories
- ๐ฏ Selective Generation: Generate all specs or target specific ones
- ๐ Unified Workflow: Single config file manages all specs
Usage
-
Configure multiple specs in
.vika.json: -
Generate all specs:
-
Generate specific spec:
-
Interactive selection (default):
# Prompts: "Which spec do you want to generate?"
Spec Naming Rules
- Use kebab-case (e.g.,
ecommerce,order-service,user-api) - Names must be unique within the
specsarray - Names are used in directory paths:
apis/{spec_name}/{module}/
โก Caching
Each spec is cached independently using its name as part of the cache key.
๐ก Backup Mode
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 fmtcargo clippy- Unit tests
- Snapshot tests
- Multi-platform builds
Releases
Semantic versioning applies:
- MAJOR = breaking changes
- MINOR = new features
- PATCH = fixes
See: CHANGELOG.md
๐ค Contributing
- Fork
- Create a feature branch
- Make changes with tests
- Submit a PR
Guide: docs/contributing.md
๐ License
MIT
๐ Links
- ๐ GitHub: https://github.com/MahdiZarrinkolah/vika-cli
- ๐ Documentation: /docs
- ๐ Issue Tracker: https://github.com/MahdiZarrinkolah/vika-cli/issues
๐ Thank You
vika-cli is now a fully production-grade OpenAPI codegen tool.
Enjoy building! ๐