Skip to main content

rh_codegen/
config.rs

1//! Configuration types and utilities for code generation
2//!
3//! This module contains configuration structures and related functionality.
4
5use rh_foundation::Config;
6use serde::{Deserialize, Serialize};
7use std::collections::HashMap;
8
9/// Configuration for the code generator
10#[derive(Debug, Serialize, Deserialize, Clone)]
11pub struct CodegenConfig {
12    /// Output directory for generated files
13    pub output_dir: String,
14    /// Module name for generated types
15    pub module_name: String,
16    /// Whether to generate serde annotations
17    pub with_serde: bool,
18    /// Whether to generate documentation
19    pub with_docs: bool,
20    /// Whether to emit macro calls for primitive types instead of regular fields
21    pub use_macro_calls: bool,
22    /// Custom type mappings from FHIR to Rust types
23    pub type_mappings: HashMap<String, String>,
24    /// Optional override for the generated crate name (e.g., "rh-hl7-fhir-r4-core").
25    /// When None, the name is auto-derived from the FHIR package name.
26    pub crate_name: Option<String>,
27}
28
29impl Default for CodegenConfig {
30    fn default() -> Self {
31        let mut type_mappings = HashMap::new();
32
33        // Common FHIR to Rust type mappings using new primitive type aliases
34        type_mappings.insert("string".to_string(), "StringType".to_string());
35        type_mappings.insert("integer".to_string(), "IntegerType".to_string());
36        type_mappings.insert("boolean".to_string(), "BooleanType".to_string());
37        type_mappings.insert("decimal".to_string(), "DecimalType".to_string());
38        type_mappings.insert("positiveInt".to_string(), "PositiveIntType".to_string());
39        type_mappings.insert("unsignedInt".to_string(), "UnsignedIntType".to_string());
40        type_mappings.insert("uri".to_string(), "StringType".to_string());
41        type_mappings.insert("url".to_string(), "StringType".to_string());
42        type_mappings.insert("canonical".to_string(), "StringType".to_string());
43        type_mappings.insert("oid".to_string(), "StringType".to_string());
44        type_mappings.insert("id".to_string(), "StringType".to_string());
45        type_mappings.insert("markdown".to_string(), "StringType".to_string());
46        type_mappings.insert("base64Binary".to_string(), "Base64BinaryType".to_string());
47        type_mappings.insert("instant".to_string(), "InstantType".to_string());
48        type_mappings.insert("date".to_string(), "DateType".to_string());
49        type_mappings.insert("dateTime".to_string(), "DateTimeType".to_string());
50        type_mappings.insert("time".to_string(), "TimeType".to_string());
51
52        Self {
53            output_dir: "generated".to_string(),
54            module_name: "fhir_types".to_string(),
55            with_serde: true,
56            with_docs: true,
57            use_macro_calls: false, // Disabled by default for backward compatibility
58            type_mappings,
59            crate_name: None,
60        }
61    }
62}
63
64impl Config for CodegenConfig {}