fix(cards): only connector and hero cards become a legacy card
- An object with just a title (golden: text 5, title, value) stayed a card and broke card_content_text - Needs @type MessageCard, sections or potentialAction, or hero buttons or images Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@@ -15,6 +15,16 @@ pub(crate) fn as_adaptive_card(root: &Value) -> Option<Value> {
15
15
if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {
16
16
return None;
17
17
}
18
let connector = text(root, "@type") == Some("MessageCard")
19
|| ["sections", "potentialAction"]
20
.iter()
21
.any(|key| root.get(key).is_some_and(Value::is_array));
22
let hero = ["buttons", "images"]
23
.iter()
24
.any(|key| root.get(key).is_some_and(Value::is_array));
25
if !connector && !hero {
26
return None;
27
}
18
28
let mut body = Vec::new();
19
29
if let Some(title) = text(root, "title") {
20
30
body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));
@@ -205,7 +215,8 @@ mod tests {
205
215
}
206
216
207
217
#[test]
208
fn an_empty_object_stays_no_card() {
218
fn an_object_without_card_shape_stays_no_card() {
209
219
assert!(AdaptiveCard::parse("{}").is_none());
220
assert!(AdaptiveCard::parse(r#"{"title": "t", "value": "v"}"#).is_none());
210
221
}
211
222
}
@@ -15,6 +15,16 @@ pub(crate) fn as_adaptive_card(root: &Value) -> Option<Value> {15
if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {15
if object.contains_key("body") || text(root, "type") == Some("AdaptiveCard") {16
return None;16
return None;17
}17
}18
let connector = text(root, "@type") == Some("MessageCard")19
|| ["sections", "potentialAction"]20
.iter()21
.any(|key| root.get(key).is_some_and(Value::is_array));22
let hero = ["buttons", "images"]23
.iter()24
.any(|key| root.get(key).is_some_and(Value::is_array));25
if !connector && !hero {26
return None;27
}18
let mut body = Vec::new();28
let mut body = Vec::new();19
if let Some(title) = text(root, "title") {29
if let Some(title) = text(root, "title") {20
body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));30
body.push(json!({"type": "TextBlock", "text": title, "weight": "Bolder", "size": "Medium", "wrap": true}));@@ -205,7 +215,8 @@ mod tests {205
}215
}206
216
207
#[test]217
#[test]208
fn an_empty_object_stays_no_card() {218
fn an_object_without_card_shape_stays_no_card() {209
assert!(AdaptiveCard::parse("{}").is_none());219
assert!(AdaptiveCard::parse("{}").is_none());220
assert!(AdaptiveCard::parse(r#"{"title": "t", "value": "v"}"#).is_none());210
}221
}211
}222
}