openapi_nexus/generators/kotlin/okhttp/
runtime.rs1use crate::codegen::traits::file_writer::FileInfo;
2
3const API_CLIENT_KT: &str = include_str!("runtime/api_client.kt.txt");
4const API_EXCEPTION_KT: &str = include_str!("runtime/api_exception.kt.txt");
5const AUTH_KT: &str = include_str!("runtime/auth.kt.txt");
6const UPLOAD_FILE_KT: &str = include_str!("runtime/upload_file.kt.txt");
7
8pub fn runtime_files(header: &str, package_name: &str, include_upload_file: bool) -> Vec<FileInfo> {
9 let runtime_package = format!("{package_name}.runtime");
10 let mut files = vec![
11 FileInfo::runtime(
12 "ApiClient.kt".to_string(),
13 repackage(header, API_CLIENT_KT, &runtime_package),
14 ),
15 FileInfo::runtime(
16 "ApiException.kt".to_string(),
17 repackage(header, API_EXCEPTION_KT, &runtime_package),
18 ),
19 FileInfo::runtime(
20 "Auth.kt".to_string(),
21 repackage(header, AUTH_KT, &runtime_package),
22 ),
23 ];
24 if include_upload_file {
25 files.push(FileInfo::runtime(
26 "UploadFile.kt".to_string(),
27 repackage(header, UPLOAD_FILE_KT, &runtime_package),
28 ));
29 }
30 files
31}
32
33fn repackage(header: &str, body: &str, runtime_package: &str) -> String {
34 let patched = body.replacen("package runtime", &format!("package {runtime_package}"), 1);
35 let mut out = String::with_capacity(header.len() + patched.len());
36 out.push_str(header);
37 out.push_str(&patched);
38 out
39}