1use crate::models::schema::*;
2use serde::{Deserialize, Serialize};
3use serde_json::Value;
4
5#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
7pub struct InputDataModelDefinition {
8 #[serde(skip_serializing_if = "Option::is_none")]
10 pub schema: Option<SchemaDefinition>,
11
12 #[serde(skip_serializing_if = "Option::is_none")]
14 pub from: Option<Value>,
15}
16
17#[cfg(test)]
18mod tests {
19 use super::*;
20
21 #[test]
22 fn test_input_with_from() {
23 let json = r#"{"from": {"key": "value"}}"#;
24 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
25 assert!(input.from.is_some());
26 assert!(input.schema.is_none());
27 }
28
29 #[test]
30 fn test_input_with_schema() {
31 let json = r#"{"schema": {"format": "json", "document": {"type": "object"}}}"#;
32 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
33 assert!(input.schema.is_some());
34 assert!(input.from.is_none());
35 }
36
37 #[test]
38 fn test_input_roundtrip() {
39 let json = r#"{"from": {"key": "value"}}"#;
40 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
41 let serialized = serde_json::to_string(&input).unwrap();
42 let deserialized: InputDataModelDefinition = serde_json::from_str(&serialized).unwrap();
43 assert_eq!(input, deserialized);
44 }
45
46 #[test]
49 fn test_input_with_from_expression() {
50 let json = r#"{"from": "${ .inputData }"}"#;
52 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
53 assert!(input.from.is_some());
54 assert_eq!(input.from.unwrap(), serde_json::json!("${ .inputData }"));
55 }
56
57 #[test]
58 fn test_input_with_schema_and_from() {
59 let json = r#"{
61 "schema": {"format": "json", "document": {"type": "object"}},
62 "from": {"key": "value"}
63 }"#;
64 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
65 assert!(input.schema.is_some());
66 assert!(input.from.is_some());
67 }
68
69 #[test]
70 fn test_input_default() {
71 let input = InputDataModelDefinition::default();
72 assert!(input.schema.is_none());
73 assert!(input.from.is_none());
74 }
75
76 #[test]
77 fn test_input_empty_object() {
78 let json = r#"{}"#;
79 let input: InputDataModelDefinition = serde_json::from_str(json).unwrap();
80 assert!(input.schema.is_none());
81 assert!(input.from.is_none());
82 }
83}