Skip to content

Commit ddfb5de

Browse files
committed
fix(wizard): accept integer examples in prompt placeholders
The previous extraction used `as_str()` only, which silently returned None for numeric JSON examples. So a schema like `"examples": [8080]` on an integer field — exactly the kind of example that would benefit from a placeholder — produced no placeholder despite the integer branch wiring one up. Widen the extraction to also accept i64 and coerce to String, then pass through call sites via `as_deref()`. No schema in runtimedb today carries numeric examples, so this is a pure consistency fix — but it aligns the code with what the original commit's description claimed to support.
1 parent 2e5944d commit ddfb5de

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/connections_new.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,16 @@ fn prompt_field(key: &str, field: &Value, is_required: bool) -> Option<Value> {
114114
let field_type = field["type"].as_str().unwrap_or("string");
115115
let format = field["format"].as_str().unwrap_or("");
116116
let description = field["description"].as_str();
117-
let example = field["examples"]
117+
// Accept both string and integer examples — `as_str` alone would silently
118+
// miss schemas like `"examples": [8080]` on integer fields.
119+
let example: Option<String> = field["examples"]
118120
.as_array()
119121
.and_then(|a| a.first())
120-
.and_then(|v| v.as_str());
122+
.and_then(|v| {
123+
v.as_str()
124+
.map(str::to_owned)
125+
.or_else(|| v.as_i64().map(|n| n.to_string()))
126+
});
121127
let opt_hint = "optional — press Enter to skip";
122128
let help_message: Option<String> = match (description, is_required) {
123129
(Some(d), true) => Some(d.to_string()),
@@ -147,7 +153,7 @@ fn prompt_field(key: &str, field: &Value, is_required: bool) -> Option<Value> {
147153
let default = field["default"].as_str();
148154
if let Some(d) = default {
149155
t = t.with_default(d);
150-
} else if let Some(e) = example {
156+
} else if let Some(e) = example.as_deref() {
151157
t = t.with_placeholder(e);
152158
}
153159
if let Some(h) = &help_message {
@@ -176,7 +182,7 @@ fn prompt_field(key: &str, field: &Value, is_required: bool) -> Option<Value> {
176182
Ok(Validation::Invalid("Must be a whole number".into()))
177183
}
178184
});
179-
if let Some(e) = example {
185+
if let Some(e) = example.as_deref() {
180186
t = t.with_placeholder(e);
181187
}
182188
if let Some(h) = &help_message {
@@ -215,7 +221,7 @@ fn prompt_field(key: &str, field: &Value, is_required: bool) -> Option<Value> {
215221
None => array_hint.to_string(),
216222
};
217223
let val = Text::new(&label)
218-
.with_placeholder(example.unwrap_or("value1, value2, ..."))
224+
.with_placeholder(example.as_deref().unwrap_or("value1, value2, ..."))
219225
.with_help_message(&help)
220226
.prompt()
221227
.unwrap_or_else(|_| std::process::exit(0));

0 commit comments

Comments
 (0)