File size: 1,883 Bytes
afa0cbf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | //! Removes the opt-in verification mode from the flattened stable elicitation union.
//!
//! `ExperimentalApi` enum annotations currently drive runtime checks only. Keep this new mode
//! out of stable exports without changing the export behavior of existing gated enum variants.
use super::extract_discriminator_from_arm;
use super::split_top_level;
use super::split_type_alias;
use serde_json::Value;
const MODE: &str = "openai/userVerification";
pub(super) fn filter_ts(content: &str) -> String {
let Some((prefix, body, suffix)) = split_type_alias(content) else {
return content.to_string();
};
let parts = split_top_level(&body, '&')
.into_iter()
.map(|part| {
let Some(union) = part
.strip_prefix('(')
.and_then(|part| part.strip_suffix(')'))
else {
return part;
};
let arms = split_top_level(union, '|')
.into_iter()
.filter(|arm| extract_discriminator_from_arm(arm, "mode").as_deref() != Some(MODE))
.collect::<Vec<_>>();
format!("({})", arms.join(" | "))
})
.collect::<Vec<_>>();
format!("{prefix} {}{suffix}", parts.join(" & "))
}
pub(super) fn filter_json(value: &mut Value) {
match value {
Value::Array(items) => {
items.retain(|item| {
item.pointer("/properties/mode/enum") != Some(&serde_json::json!([MODE]))
});
for item in items {
filter_json(item);
}
}
Value::Object(map) => {
for entry in map.values_mut() {
filter_json(entry);
}
}
Value::Null | Value::Bool(_) | Value::Number(_) | Value::String(_) => {}
}
}
#[cfg(test)]
#[path = "export_user_verification_tests.rs"]
mod tests;
|