cli: compact schema output by default and tighten field docs

This commit is contained in:
Gregory Schier
2026-02-22 16:18:29 -08:00
parent c31d477a90
commit 1e7e1232da
4 changed files with 34 additions and 6 deletions

View File

@@ -154,6 +154,10 @@ pub enum RequestCommands {
Schema {
#[arg(value_enum)]
request_type: RequestSchemaType,
/// Pretty-print schema JSON output
#[arg(long)]
pretty: bool,
},
/// Create a new HTTP request

View File

@@ -35,8 +35,8 @@ pub async fn run(
}
};
}
RequestCommands::Schema { request_type } => {
return match schema(ctx, request_type).await {
RequestCommands::Schema { request_type, pretty } => {
return match schema(ctx, request_type, pretty).await {
Ok(()) => 0,
Err(error) => {
eprintln!("Error: {error}");
@@ -75,7 +75,7 @@ fn list(ctx: &CliContext, workspace_id: &str) -> CommandResult {
Ok(())
}
async fn schema(ctx: &CliContext, request_type: RequestSchemaType) -> CommandResult {
async fn schema(ctx: &CliContext, request_type: RequestSchemaType, pretty: bool) -> CommandResult {
let mut schema = match request_type {
RequestSchemaType::Http => serde_json::to_value(schema_for!(HttpRequest))
.map_err(|e| format!("Failed to serialize HTTP request schema: {e}"))?,
@@ -91,7 +91,11 @@ async fn schema(ctx: &CliContext, request_type: RequestSchemaType) -> CommandRes
eprintln!("Warning: Failed to enrich authentication schema from plugins: {error}");
}
let output = serde_json::to_string_pretty(&schema)
let output = if pretty {
serde_json::to_string_pretty(&schema)
} else {
serde_json::to_string(&schema)
}
.map_err(|e| format!("Failed to format schema JSON: {e}"))?;
println!("{output}");
Ok(())

View File

@@ -189,12 +189,25 @@ fn request_schema_http_outputs_json_schema() {
.args(["request", "schema", "http"])
.assert()
.success()
.stdout(contains("\"type\": \"object\""))
.stdout(contains("\"authentication\""))
.stdout(contains("\"type\":\"object\""))
.stdout(contains("\"authentication\":"))
.stdout(contains("/foo/:id/comments/:commentId"))
.stdout(contains("put concrete values in `urlParameters`"));
}
#[test]
fn request_schema_http_pretty_prints_with_flag() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let data_dir = temp_dir.path();
cli_cmd(data_dir)
.args(["request", "schema", "http", "--pretty"])
.assert()
.success()
.stdout(contains("\"type\": \"object\""))
.stdout(contains("\"authentication\""));
}
#[test]
fn request_send_grpc_returns_explicit_nyi_error() {
let temp_dir = TempDir::new().expect("Failed to create temp dir");