use crate::codegen::traits::file_writer::FileInfo;
use crate::ir::types::IrInfo;
use heck::ToKebabCase as _;
pub fn render_file_header(info: &IrInfo) -> String {
let mut out = String::new();
out.push_str("// @generated\n");
out.push_str("// Code generated by openapi-nexus. DO NOT EDIT.\n");
out.push_str("//\n");
out.push_str(&format!("// {} — {}\n", info.title, info.version));
if let Some(desc) = &info.description {
for line in desc.lines() {
out.push_str(&format!("// {line}\n"));
}
}
out.push('\n');
out
}
pub fn lib_rs_file(header: &str) -> FileInfo {
let content = format!(
"{header}#![allow(clippy::all)]\n\npub mod apis;\npub mod models;\npub mod runtime;\n"
);
FileInfo::project("src/lib.rs".to_string(), content)
}
pub fn readme_file(info: &IrInfo) -> FileInfo {
let title = &info.title;
let version = &info.version;
let description = info
.description
.clone()
.unwrap_or_else(|| "Generated Rust SDK.".to_string());
let crate_name = info.title.to_kebab_case();
let content = format!(
"# {title}\n\n{description}\n\nVersion: `{version}`\n\nGenerated by [openapi-nexus](https://github.com/adamcavendish/openapi-nexus) for `{crate_name}`.\n"
);
FileInfo::readme("README.md".to_string(), content)
}
pub fn with_header(header: &str, body: &str) -> String {
let mut out = String::with_capacity(header.len() + body.len());
out.push_str(header);
out.push_str(body);
out
}