# ๐ vika-cli
### A blazing-fast Rust-powered OpenAPI code generator that produces TypeScript types, Zod schemas, and Fetch clients โ designed for real-world DX.
[](https://github.com/MahdiZarrinkolah/vika-cli/actions)
[](LICENSE)
`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
| **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)
```bash
### Windows (PowerShell)
```powershell
### Cargo
```bash
cargo install vika-cli
```
### From Source
```bash
git clone https://github.com/MahdiZarrinkolah/vika-cli
cd vika-cli
cargo build --release
```
---
# ๐ Quick Start
## 1๏ธ Initialize a project
```bash
vika-cli init
```
Creates a `.vika.json` configuration file.
## 2๏ธ Generate code from an OpenAPI specification
Remote:
```bash
vika-cli generate --spec https://example.com/openapi.json
```
Local:
```bash
vika-cli generate --spec ./swagger.yaml
```
Flags:
| `--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
```bash
vika-cli update
```
## 4๏ธ Inspect a specification (no generation)
```bash
vika-cli inspect --spec ./swagger.yaml
```
Examples:
```bash
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`)
```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
| `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`](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
```ts
export interface ProductDto {
id: string;
price: number;
title: string;
}
```
### Zod Schema
```ts
export const ProductDtoSchema = z.object({
id: z.string(),
price: z.number(),
title: z.string(),
});
```
### Fetch API Client
```ts
export const getProduct = async (id: string): Promise<ProductDto> =>
http.get(`/products/${id}`);
```
---
# ๐งฉ Advanced Features
### โก Caching
```bash
vika-cli generate --cache
```
### ๐ก Backup Mode
```bash
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`](docs/architecture.md)
---
# ๐ Development & Release
### CI includes:
- `cargo fmt`
- `cargo clippy`
- Unit tests
- Snapshot tests
- Multi-platform builds
### Releases
```bash
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`](docs/contributing.md)
---
# ๐ License
MIT
---
# ๐ Links
- ๐ **GitHub**: [https://github.com/MahdiZarrinkolah/vika-cli](https://github.com/MahdiZarrinkolah/vika-cli)
- ๐ **Documentation**: /docs
- ๐ **Issue Tracker**: [https://github.com/MahdiZarrinkolah/vika-cli/issues](https://github.com/MahdiZarrinkolah/vika-cli/issues)
---
# ๐ Thank You
`vika-cli` is now a fully production-grade OpenAPI codegen tool.
Enjoy building! ๐