Skip to content

Vijayabaskar56/openapi-porter

Repository files navigation

openapi-2-cli

Vibe coded with Claude

A CLI generator that creates native command-line interfaces from OpenAPI specifications. Extract specs from documentation pages and compile them into standalone binaries with man pages.

The Problem

AI agents like Claude can interact with terminal commands far more easily than web interfaces. Browser automation is slow, brittle, and extremely token-hungry - every page load, click, and form fill burns through context.

But most tools today are web-first. They have beautiful dashboards, but no CLI.

The solution: If a tool has OpenAPI/Swagger documentation (and many do), we can automatically generate a CLI from it. Now your AI agent can interact with that tool through simple terminal commands instead of wrestling with browser automation.

# Instead of this (browser automation nightmare):
agent.click("Login button")
agent.fill("email", "user@example.com")
agent.wait_for_page_load()
agent.click("Dashboard")
agent.find_element(".user-list")...

# You get this (clean CLI):
./mytool users list
./mytool users get 123

Features

  • Extract OpenAPI specs from various documentation formats (Swagger UI, Redoc, Scalar, or direct JSON/YAML)
  • Generate type-safe CLI tools from OpenAPI specifications
  • Compile to native binaries using Bun
  • Auto-generate man pages for documentation
  • Support for authentication configuration
  • Resource-based command structure (e.g., myapi users list, myapi users get <id>)

Installation

bun install

Usage

Extract OpenAPI Spec

Extract an OpenAPI specification from a documentation URL:

bun run index.ts extract <url>

Generate CLI

Generate a CLI binary from an OpenAPI spec (URL or local file):

bun run index.ts generate <url-or-file> [options]

Options:

Option Description
--name <name> CLI name (default: derived from spec title)
--output <dir> Output directory (default: current directory)
--force Overwrite existing files

Examples:

# Generate from a documentation URL
bun run index.ts generate https://api.example.com/docs --name myapi --output ./bin/

# Generate from a local OpenAPI spec file
bun run index.ts generate ./openapi.json --name myapi

# Overwrite existing binary
bun run index.ts generate ./openapi.json --name myapi --force

Using Generated CLIs

Once generated, your CLI supports:

# Get help
./myapi --help

# Configure authentication
./myapi config set token <your-api-token>

# Make API calls
./myapi users list
./myapi users get 123

Scripts

# Run the CLI
bun run start

# Run tests
bun run test

# Type check
bun run typecheck

# Build binary
bun run build

Project Structure

openapi-2-cli/
├── index.ts              # Main entry point
├── src/
│   ├── types.ts          # Type definitions
│   ├── detector.ts       # OpenAPI format detection
│   ├── extractors.ts     # Spec extraction logic
│   ├── generator/
│   │   ├── parser.ts     # OpenAPI spec parser
│   │   ├── template.ts   # CLI source code generator
│   │   ├── compiler.ts   # Bun binary compiler
│   │   ├── man-page.ts   # Man page generator
│   │   ├── resource-mapper.ts  # REST resource mapping
│   │   └── types.ts      # Generator types
│   └── runtime/
│       ├── config.ts     # Runtime configuration
│       ├── http.ts       # HTTP client
│       └── output.ts     # Output formatting

Roadmap

  • Auto-generate Claude Code skills - Generate a skill file alongside each CLI so agents can discover and use commands with proper context
  • Optimize binary size - Reduce compiled CLI size through tree-shaking, minification, and removing unused runtime code
  • Better AI agent integration - First-class support for Claude Code, including MCP server generation and tool definitions
  • Authentication presets - Built-in support for common auth patterns (OAuth2, API keys, JWT)
  • Interactive mode - REPL-style interface for exploring APIs
  • Response caching - Cache responses for read operations to reduce API calls

Requirements

  • Bun v1.0 or later

License

MIT

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors