in compiler-rs/clients_schema_to_openapi/src/main.rs [69:110]
fn run(self) -> anyhow::Result<()> {
let json = if self.schema == Path::new("-") {
std::io::read_to_string(std::io::stdin())?
} else {
std::fs::read_to_string(self.schema)?
};
let model: clients_schema::IndexedModel = match serde_json::from_str(&json) {
Ok(indexed_model) => indexed_model,
Err(e) => bail!("cannot parse schema json: {}", e)
};
let flavor = match self.flavor {
Some(SchemaFlavor::All) | None => None,
Some(SchemaFlavor::Stack) => Some(Flavor::Stack),
Some(SchemaFlavor::Serverless) => Some(Flavor::Serverless),
};
let config = Configuration {
flavor,
..Default::default()
};
let openapi = clients_schema_to_openapi::convert_schema(model, config)?;
let output: Box<dyn std::io::Write> = {
if let Some(output) = self.output {
if output == Path::new("-") {
Box::new(std::io::stdout())
} else {
Box::new(std::fs::File::create(output)?)
}
} else {
Box::new(std::io::stdout())
}
};
let output = std::io::BufWriter::new(output);
serde_json::to_writer_pretty(output, &openapi)?;
Ok(())
}