conductor/models/
schema.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
8#[serde(rename_all = "camelCase")]
9pub struct SchemaDef {
10 pub name: String,
12
13 pub version: i32,
15
16 #[serde(rename = "type", default = "default_schema_type")]
18 pub schema_type: String,
19
20 #[serde(default)]
22 pub data: serde_json::Value,
23
24 #[serde(default)]
26 pub external_ref: bool,
27
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub create_time: Option<i64>,
31
32 #[serde(skip_serializing_if = "Option::is_none")]
34 pub created_by: Option<String>,
35
36 #[serde(skip_serializing_if = "Option::is_none")]
38 pub update_time: Option<i64>,
39
40 #[serde(skip_serializing_if = "Option::is_none")]
42 pub updated_by: Option<String>,
43}
44
45fn default_schema_type() -> String {
46 "JSON".to_owned()
47}
48
49impl SchemaDef {
50 pub fn new(name: impl Into<String>, version: i32, data: serde_json::Value) -> Self {
52 Self {
53 name: name.into(),
54 version,
55 schema_type: default_schema_type(),
56 data,
57 ..Default::default()
58 }
59 }
60
61 pub fn json_schema(name: impl Into<String>, version: i32, schema: serde_json::Value) -> Self {
63 Self {
64 name: name.into(),
65 version,
66 schema_type: "JSON".to_owned(),
67 data: schema,
68 ..Default::default()
69 }
70 }
71}