1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
mod generator;
mod source;

pub use generator::*;
pub use source::*;

use serde::Serialize;

pub fn config_to_mcf_json_value(mcf: &crate::Configuration) -> serde_json::Value {
    serde_json::to_value(&model_to_serializable(mcf)).expect("Failed to render JSON.")
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SerializeableMcf {
    generators: serde_json::Value,
    datasources: serde_json::Value,
    warnings: Vec<String>,
}

fn model_to_serializable(config: &crate::Configuration) -> SerializeableMcf {
    SerializeableMcf {
        generators: generator::generators_to_json_value(&config.generators),
        datasources: source::render_sources_to_json_value(&config.datasources),
        warnings: config.warnings.iter().map(|f| f.message().to_owned()).collect(),
    }
}