rescript_openapi/codegen/
mod.rs1pub mod client;
12pub mod schema;
13pub mod types;
14
15use anyhow::Result;
16use serde::{Deserialize, Serialize};
17use std::fs;
18use std::path::PathBuf;
19
20#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
21#[serde(rename_all = "kebab-case")]
22pub enum ClientMode {
23 Full,
25 FunctorOnly,
27 None,
29}
30
31#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)]
32#[serde(rename_all = "kebab-case")]
33pub enum VariantMode {
34 Polymorphic,
36 Standard,
38}
39
40pub struct Config {
41 pub output_dir: PathBuf,
42 pub module_prefix: String,
43 pub generate_schema: bool,
44 pub generate_client: bool,
45 pub unified_module: bool,
46 pub client_mode: ClientMode,
47 pub variant_mode: VariantMode,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ProjectConfig {
52 pub input: Option<PathBuf>,
53 pub output: Option<PathBuf>,
54 pub module: Option<String>,
55 pub with_schema: Option<bool>,
56 pub with_client: Option<bool>,
57 pub unified: Option<bool>,
58 pub client_mode: Option<ClientMode>,
59 pub variant_mode: Option<VariantMode>,
60}
61
62impl ProjectConfig {
63 pub fn load(path: &std::path::Path) -> Result<Self> {
64 let content = fs::read_to_string(path)?;
65 let config: Self = toml::from_str(&content)?;
66 Ok(config)
67 }
68}
69