openapi-clap
Auto-generate clap CLI commands from OpenAPI specs.
Given a dereferenced OpenAPI 3.x JSON document, openapi-clap extracts operations into an intermediate representation, builds a clap Command tree, and dispatches HTTP requests -- turning any REST API into a CLI with zero hand-written argument definitions.
Features
- Spec-driven: paths, parameters (path / query / header), and request bodies are mapped to clap subcommands and arguments automatically.
- Grouped by tag: operations are organized under tag-based subcommands (e.g.
mycli pods list-pods). - Body input: supports
--json '{...}'for raw JSON and--field key=valuefor individual fields. - Customizable:
CliConfiglets you set the root command name, description, and default base URL. - Re-exports:
clapandreqwestare re-exported so downstream crates can avoid version conflicts.
Quick start
Add to your Cargo.toml:
[]
= "0.1"
= "0.1"
= "1"
Build and dispatch:
use ;
use resolve;
use Client;
How it works
- Parse --
extract_operations()walks the OpenAPIpathsobject and produces aVec<ApiOperation>. - Build --
build_commands()converts operations into a clapCommandtree grouped by tag. - Match --
find_operation()resolves the user's subcommand back to the originalApiOperation. - Dispatch --
dispatch()constructs and sends the HTTP request, returning the response asserde_json::Value.
License
Licensed under either of
at your option.