| Crates.io | vika-cli |
| lib.rs | vika-cli |
| version | 1.4.0 |
| created_at | 2025-11-22 13:52:29.390544+00 |
| updated_at | 2025-11-26 13:10:43.707445+00 |
| description | Generate TypeScript types, Zod schemas, and Fetch-based API clients from OpenAPI/Swagger specifications |
| homepage | |
| repository | https://github.com/MahdiZarrinkolah/vika-cli |
| max_upload_size | |
| id | 1945373 |
| size | 912,094 |
vika-cli is a blazing-fast, production-grade code generator that transforms any Swagger/OpenAPI specification into fully typed:
Built in Rust for exceptional performance and reliability.
.vika.json)| 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?
curl -fsSL https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.sh | sh
irm https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.ps1 | iex
cargo install vika-cli
git clone https://github.com/MahdiZarrinkolah/vika-cli
cd vika-cli
cargo build --release
vika-cli init
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.
# Interactive selection (default)
vika-cli generate
# Force a specific spec
vika-cli generate --spec ecommerce
# Regenerate everything
vika-cli generate --all-specs
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:
vika-cli update
vika-cli inspect --spec ./swagger.yaml
# Inspect all specs
vika-cli inspect --all-specs
# Inspect specific spec by name
vika-cli inspect --spec ecommerce
Examples:
# Single spec mode
vika-cli inspect --spec ./swagger.yaml --module products
vika-cli inspect --spec ./swagger.yaml --schemas
vika-cli inspect --spec ./swagger.yaml --json
# Multi-spec mode
vika-cli inspect --spec admin --schemas
vika-cli inspect --all-specs --json
vika-cli uses a robust generation pipeline:
Reads OpenAPI 3.x JSON/YAML.
Groups endpoints by Swagger tags.
Resolves:
$refProduces:
.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.
{
"$schema": "https://raw.githubusercontent.com/vikarno/vika-cli/main/schema/vika-config.schema.json",
"root_dir": "src",
"generation": {
"enable_cache": true,
"enable_backup": false,
"conflict_strategy": "ask"
},
"specs": [
{
"name": "ecommerce",
"path": "http://localhost:3000/swagger-ecommerce.json",
"schemas": {
"output": "src/schemas/ecommerce",
"naming": "PascalCase"
},
"apis": {
"output": "src/apis/ecommerce",
"style": "fetch",
"base_url": "https://api.example.com",
"header_strategy": "consumerInjected"
},
"modules": {
"ignore": [],
"selected": ["orders", "payments", "users"]
}
}
]
}
| 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. |
| 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
vika-cli uses Tera templates for code generation. You can customize the output format by overriding built-in templates.
Initialize templates (copies built-in templates to .vika/templates/):
vika-cli templates init
List available templates:
vika-cli templates list
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:
vika-cli generate --spec your-spec.yaml
type-interface.tera - TypeScript interface generationtype-enum.tera - TypeScript enum generationzod-schema.tera - Zod schema generationapi-client-fetch.tera - API client function generationTemplate Resolution: User templates in .vika/templates/ override built-in templates automatically.
Full documentation: docs/templates.md
๐ 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
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:
File types:
ProductDto, UserProfile, etc.)ProductDtoSchema, etc.)export interface ProductDto {
id: string;
price: number;
title: string;
}
export const ProductDtoSchema = z.object({
id: z.string(),
price: z.number(),
title: z.string(),
});
export const getProduct = async (id: string): Promise<ProductDto> =>
http.get(`/products/${id}`);
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.
Configure multiple specs in .vika.json:
{
"specs": [
{ "name": "ecommerce", "path": "http://localhost:3000/swagger-ecommerce.json" },
{ "name": "admin", "path": "http://localhost:3000/swagger-admin.json" },
{ "name": "public", "path": "http://localhost:3000/swagger-public.json" }
]
}
Generate all specs:
vika-cli generate --all-specs
Generate specific spec:
vika-cli generate --spec ecommerce
Interactive selection (default):
vika-cli generate
# Prompts: "Which spec do you want to generate?"
ecommerce, order-service, user-api)specs arrayapis/{spec_name}/{module}/vika-cli generate --cache
Each spec is cached independently using its name as part of the cache key.
vika-cli generate --backup
Backups stored in:
.vika-backup/<timestamp>/
Warns if manually modified files would be overwritten.
Using insta for generator correctness.
.vika.jsonDetails: docs/architecture.md
cargo fmtcargo clippycargo release patch
Semantic versioning applies:
See: CHANGELOG.md
Guide: docs/contributing.md
MIT
vika-cli is now a fully production-grade OpenAPI codegen tool.
Enjoy building! ๐