vika-cli
A production-grade Rust CLI tool that generates TypeScript typings, Zod schemas, and Fetch-based API clients from Swagger/OpenAPI specifications.
Features
- 🚀 Generate TypeScript interfaces from OpenAPI schemas
- ✅ Generate Zod validation schemas
- 🔌 Generate Fetch-based HTTP client functions
- 📦 Module-based code generation (grouped by Swagger tags)
- 🎯 Interactive module selection
- ⚙️ Configurable output directories
- 🎨 Progress indicators and verbose mode
- 💾 Spec caching for faster regeneration
- 🔄 Backup system for generated files
- 🛡️ Conflict detection for user-modified files
- 🔍 Inspect command for analyzing OpenAPI specs
- 🎯 Support for HEAD, OPTIONS HTTP methods
- 📊 Formatted table output for module summaries
Installation
Quick Install (macOS/Linux)
|
Windows (PowerShell)
irm https://github.com/MahdiZarrinkolah/vika-cli/releases/latest/download/install.ps1 | iex
Cargo
Build from Source
Getting Started
1. Initialize a project
This creates a .vika.json configuration file and sets up the project structure.
2. Generate code from Swagger spec
Or from a local file:
Available flags:
--verbose: Enable verbose output with detailed progress information--cache: Use cached spec if available (faster for remote specs)--backup: Create backup of existing files before writing--force: Force overwrite user-modified files
The tool will:
- Fetch and parse the Swagger/OpenAPI spec (with optional caching)
- Display available modules (tags)
- Let you interactively select which modules to generate
- Generate TypeScript types, Zod schemas, and API client functions
- Show formatted table summary of generated files
3. Update generated code
Regenerates code for previously selected modules without interactive prompts.
4. Inspect OpenAPI spec
Analyze an OpenAPI spec without generating code:
# Show all modules
# Show specific module details
# Show schema details
# JSON output
How Generation Works
vika-cli follows a multi-stage generation pipeline:
- Spec Parsing: Fetches and parses OpenAPI/Swagger specifications (supports JSON and YAML)
- Module Extraction: Groups endpoints by tags, creating logical modules
- Schema Resolution: Resolves
$refreferences and builds dependency graphs - Type Generation: Converts OpenAPI schemas to TypeScript interfaces
- Zod Generation: Creates Zod validation schemas from OpenAPI constraints
- API Client Generation: Generates type-safe Fetch-based API functions
- File Writing: Writes generated code with conflict detection and backup support
The generator handles:
- Circular dependencies (detected and handled gracefully)
- Deep nesting (unlimited depth)
- Union types (
oneOf,anyOf) - AllOf composition
- Enums and string constraints
- Optional vs required fields
- Nullable types
Configuration
The .vika.json configuration file:
Configuration Options
rootDir: Root directory for generated filesschemas.output: Output directory for TypeScript types and Zod schemasschemas.naming: Naming convention for schemas (PascalCase,camelCase,snake_case)apis.output: Output directory for API client functionsapis.style: API client style (currently only "fetch" is supported)apis.baseUrl: Base URL prefix for API endpoints (supports${ENV_VAR}substitution)apis.headerStrategy: Header generation strategy (bearerToken,fixed,consumerInjected)modules.ignore: List of module tags to ignore during generation
See docs/configuration.md for complete configuration reference.
Generated Code Structure
src/
├── schemas/
│ └── <module>/
│ ├── types.ts # TypeScript interfaces
│ ├── schemas.ts # Zod validation schemas
│ └── index.ts # Barrel exports
└── apis/
├── http.ts # HTTP client utility
└── <module>/
└── index.ts # API client functions
Example Generated Code
TypeScript Types
export interface ProductDto {
id: string;
price: number;
title: string;
}
Zod Schemas
import { z } from "zod";
export const ProductDtoSchema = z.object({
id: z.string(),
price: z.number(),
title: z.string(),
});
API Client Functions
import { http } from "../http";
export const getProduct = async (id: string): Promise<ProductDto> => {
const url = `/products/${id}`;
return http.get<ProductDto>(url);
};
Customizing Output
Template System
vika-cli uses templates for code generation. Templates are located in src/templates/:
http_client.ts: HTTP client utility templateindex.ts: Barrel export template
To customize output, you can modify these templates. See docs/templates.md for details.
Naming Conventions
Control how schemas are named using the schemas.naming config option:
PascalCase:UserProfile(default)camelCase:userProfilesnake_case:user_profile
Header Strategies
Configure how authentication headers are generated:
bearerToken: AddsAuthorization: Bearer ${token}headerfixed: Adds fixed headers from configconsumerInjected: Expects headers to be injected by consumer
Advanced Features
Caching
The tool caches downloaded OpenAPI specs in .vika-cache/ for faster regeneration:
Backup System
Create backups before overwriting files:
Backups are stored in .vika-backup/TIMESTAMP/ with preserved directory structure.
Conflict Detection
The tool detects if generated files were modified by the user and warns before overwriting. Use --force to override:
Error Handling
All errors are structured and provide clear messages. Common error types:
- Schema errors (missing references, circular dependencies)
- Config errors (invalid paths, missing fields)
- Network errors (fetch failures, invalid URLs)
- File system errors (permission denied, disk full)
Examples
Real-World Usage
# Generate from remote API
# Generate specific modules only
# Then select modules interactively
# Update after API changes
# Inspect before generating
See docs/getting-started.md for more examples.
Troubleshooting
Common Issues
Problem: "Spec path required" error
- Solution: Ensure you provide
--specflag or setspec_pathin.vika.json
Problem: Circular dependency warnings
- Solution: This is handled automatically. The generator uses lazy references for circular deps.
Problem: Generated files conflict with user modifications
- Solution: Use
--forceto overwrite, or--backupto create backups first
Problem: Network errors when fetching remote specs
- Solution: Check your internet connection, or use
--cachewith a previously cached spec
See docs/troubleshooting.md for more solutions.
Architecture
vika-cli is built with a modular architecture:
- CLI Layer: Command parsing and user interaction (
src/cli.rs,src/commands/) - Generator Core: Code generation logic (
src/generator/) - Config System: Configuration management (
src/config/) - Error Handling: Structured error types (
src/error.rs) - Utilities: Caching, progress reporting, formatting (
src/cache.rs,src/progress.rs,src/formatter.rs)
See docs/architecture.md for detailed architecture documentation.
Versioning
vika-cli follows Semantic Versioning:
- Major (x.0.0): Breaking changes to generated code format, CLI interface changes
- Minor (0.x.0): New features, new generation options, backward-compatible additions
- Patch (0.0.x): Bug fixes, performance improvements, documentation updates
Automated Versioning
Version bumping and changelog updates are automated:
# Using cargo-release (recommended)
📖 See RELEASE.md for complete release process documentation.
Quick references:
- docs/development/release-quick-start.md - Quick start guide
- docs/development/release-setup.md - Setup instructions
See CHANGELOG.md for version history.
Contributing
Contributions are welcome! Please see docs/contributing.md for guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
Requirements
- Rust 1.70+ (for building)
- Node.js/TypeScript project (for generated code)
License
MIT