use std::collections::BTreeSet;
use serde_json::Value;
pub fn derive(spec: &Value) -> Result<Vec<String>, String> {
let paths: BTreeSet<&str> = spec
.get("paths")
.and_then(Value::as_object)
.into_iter()
.flatten()
.filter(|(_, item)| {
item.as_object().is_some_and(|ops| {
ops.values()
.any(|op| op.get("x-twitter-streaming") == Some(&Value::Bool(true)))
})
})
.map(|(path, _)| path.as_str())
.collect();
if paths.is_empty() {
return Err(
"no operation carries `x-twitter-streaming: true`, so no endpoint would \
stream without --stream; check that the spec refresh kept the extension"
.to_string(),
);
}
Ok(paths.into_iter().map(str::to_string).collect())
}