datafake_rs/
types.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3use std::collections::HashMap;
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct DataFakeConfig {
7    #[serde(default, skip_serializing_if = "Option::is_none")]
8    pub metadata: Option<Metadata>,
9
10    #[serde(default)]
11    pub variables: HashMap<String, Value>,
12
13    pub schema: Value,
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct Metadata {
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub name: Option<String>,
20
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub version: Option<String>,
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub description: Option<String>,
26
27    #[serde(flatten)]
28    pub extra: HashMap<String, Value>,
29}
30
31#[derive(Debug, Clone)]
32pub struct GenerationContext {
33    pub variables: HashMap<String, Value>,
34}
35
36impl GenerationContext {
37    pub fn new() -> Self {
38        Self {
39            variables: HashMap::new(),
40        }
41    }
42
43    pub fn with_variables(variables: HashMap<String, Value>) -> Self {
44        Self { variables }
45    }
46
47    pub fn get_variable(&self, name: &str) -> Option<&Value> {
48        self.variables.get(name)
49    }
50
51    pub fn set_variable(&mut self, name: String, value: Value) {
52        self.variables.insert(name, value);
53    }
54}
55
56impl Default for GenerationContext {
57    fn default() -> Self {
58        Self::new()
59    }
60}