Skip to content

Commit 1e7e123

Browse files
committed
cli: compact schema output by default and tighten field docs
1 parent c31d477 commit 1e7e123

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

crates-cli/yaak-cli/src/cli.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ pub enum RequestCommands {
154154
Schema {
155155
#[arg(value_enum)]
156156
request_type: RequestSchemaType,
157+
158+
/// Pretty-print schema JSON output
159+
#[arg(long)]
160+
pretty: bool,
157161
},
158162

159163
/// Create a new HTTP request

crates-cli/yaak-cli/src/commands/request.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub async fn run(
3535
}
3636
};
3737
}
38-
RequestCommands::Schema { request_type } => {
39-
return match schema(ctx, request_type).await {
38+
RequestCommands::Schema { request_type, pretty } => {
39+
return match schema(ctx, request_type, pretty).await {
4040
Ok(()) => 0,
4141
Err(error) => {
4242
eprintln!("Error: {error}");
@@ -75,7 +75,7 @@ fn list(ctx: &CliContext, workspace_id: &str) -> CommandResult {
7575
Ok(())
7676
}
7777

78-
async fn schema(ctx: &CliContext, request_type: RequestSchemaType) -> CommandResult {
78+
async fn schema(ctx: &CliContext, request_type: RequestSchemaType, pretty: bool) -> CommandResult {
7979
let mut schema = match request_type {
8080
RequestSchemaType::Http => serde_json::to_value(schema_for!(HttpRequest))
8181
.map_err(|e| format!("Failed to serialize HTTP request schema: {e}"))?,
@@ -91,7 +91,11 @@ async fn schema(ctx: &CliContext, request_type: RequestSchemaType) -> CommandRes
9191
eprintln!("Warning: Failed to enrich authentication schema from plugins: {error}");
9292
}
9393

94-
let output = serde_json::to_string_pretty(&schema)
94+
let output = if pretty {
95+
serde_json::to_string_pretty(&schema)
96+
} else {
97+
serde_json::to_string(&schema)
98+
}
9599
.map_err(|e| format!("Failed to format schema JSON: {e}"))?;
96100
println!("{output}");
97101
Ok(())

crates-cli/yaak-cli/tests/request_commands.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,25 @@ fn request_schema_http_outputs_json_schema() {
189189
.args(["request", "schema", "http"])
190190
.assert()
191191
.success()
192-
.stdout(contains("\"type\": \"object\""))
193-
.stdout(contains("\"authentication\""))
192+
.stdout(contains("\"type\":\"object\""))
193+
.stdout(contains("\"authentication\":"))
194194
.stdout(contains("/foo/:id/comments/:commentId"))
195195
.stdout(contains("put concrete values in `urlParameters`"));
196196
}
197197

198+
#[test]
199+
fn request_schema_http_pretty_prints_with_flag() {
200+
let temp_dir = TempDir::new().expect("Failed to create temp dir");
201+
let data_dir = temp_dir.path();
202+
203+
cli_cmd(data_dir)
204+
.args(["request", "schema", "http", "--pretty"])
205+
.assert()
206+
.success()
207+
.stdout(contains("\"type\": \"object\""))
208+
.stdout(contains("\"authentication\""));
209+
}
210+
198211
#[test]
199212
fn request_send_grpc_returns_explicit_nyi_error() {
200213
let temp_dir = TempDir::new().expect("Failed to create temp dir");

crates/yaak-models/src/models.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,8 @@ pub struct Environment {
611611
pub base: bool,
612612
pub parent_model: String,
613613
pub parent_id: Option<String>,
614+
/// Variables defined in this environment scope.
615+
/// Child environments override parent variables by name.
614616
pub variables: Vec<EnvironmentVariable>,
615617
pub color: Option<String>,
616618
pub sort_priority: f64,
@@ -845,6 +847,8 @@ pub struct HttpUrlParameter {
845847
#[serde(default = "default_true")]
846848
#[ts(optional, as = "Option<bool>")]
847849
pub enabled: bool,
850+
/// Colon-prefixed parameters are treated as path parameters if they match, like `/users/:id`
851+
/// Other entries are appended as query parameters
848852
pub name: String,
849853
pub value: String,
850854
#[ts(optional, as = "Option<String>")]
@@ -877,6 +881,7 @@ pub struct HttpRequest {
877881
pub name: String,
878882
pub sort_priority: f64,
879883
pub url: String,
884+
/// URL parameters used for both path placeholders (`:id`) and query string entries.
880885
pub url_parameters: Vec<HttpUrlParameter>,
881886
}
882887

@@ -1118,6 +1123,7 @@ pub struct WebsocketRequest {
11181123
pub name: String,
11191124
pub sort_priority: f64,
11201125
pub url: String,
1126+
/// URL parameters used for both path placeholders (`:id`) and query string entries.
11211127
pub url_parameters: Vec<HttpUrlParameter>,
11221128
}
11231129

@@ -1728,6 +1734,7 @@ pub struct GrpcRequest {
17281734
pub name: String,
17291735
pub service: Option<String>,
17301736
pub sort_priority: f64,
1737+
/// Server URL (http for plaintext or https for secure)
17311738
pub url: String,
17321739
}
17331740

0 commit comments

Comments
 (0)