Skip to main content

Crate openapi_clap

Crate openapi_clap 

Source
Expand description

Auto-generate clap CLI commands from OpenAPI specs.

Parses a dereferenced OpenAPI JSON, extracts operations into an IR, builds a clap Command tree, and dispatches HTTP requests.

§Usage

use openapi_clap::{CliConfig, build_commands, extract_operations, find_operation, dispatch};
use openapi_deref::resolve;
use reqwest::blocking::Client;

let spec_json = r#"{"openapi":"3.0.0","paths":{}}"#;
let raw: serde_json::Value = serde_json::from_str(spec_json).unwrap();
let resolved = resolve(&raw).unwrap();
let ops = extract_operations(&resolved.value);

let config = CliConfig::new("myapi", "My API CLI", "https://api.example.com");

let cmd = build_commands(&config, &ops);

Re-exports§

pub use builder::build_commands;
pub use builder::find_operation;
pub use builder::normalize_group;
pub use builder::normalize_operation_id;
pub use builder::CliConfig;
pub use dispatch::dispatch;
pub use error::DispatchError;
pub use spec::extract_operations;
pub use spec::is_bool_schema;
pub use spec::ApiOperation;
pub use spec::Param;
pub use clap;
pub use reqwest;

Modules§

builder
IR → clap Command tree builder
dispatch
ArgMatches → HTTP request dispatch
error
Error types for the openapi-clap crate.
spec
OpenAPI spec → internal IR (intermediate representation)