mod format;
pub mod openapi;
pub mod python;
pub mod rust;
pub mod typescript;
use std::{
hash::{DefaultHasher, Hasher},
path::PathBuf,
};
use self::format::format_with;
#[derive(Debug, Default)]
pub struct Config {
pub format: bool,
pub typecheck: bool,
pub tracing: bool,
pub shared_modules: Vec<String>,
}
fn tmp_path(src: &str) -> PathBuf {
let mut hasher = DefaultHasher::new();
hasher.write(src.as_bytes());
let hash = hasher.finish();
std::env::temp_dir().join(format!("reflectapi-{hash}"))
}
const START_BOILERPLATE: &str = "/* <----- */";
const END_BOILERPLATE: &str = "/* -----> */";
#[doc(hidden)]
pub fn strip_boilerplate(src: &str) -> String {
let mut stripped = String::new();
let mut skip = false;
for line in src.lines() {
if line.contains(START_BOILERPLATE) {
assert!(!skip, "nested start boilerplate markers");
skip = true;
continue;
}
if line.contains(END_BOILERPLATE) {
assert!(skip, "unmatched end boilerplate marker");
skip = false;
continue;
}
if !skip {
stripped.push_str(line);
stripped.push('\n');
}
}
if skip {
panic!("unmatched boilerplate marker");
}
stripped
}