Skip to content

Commit a146326

Browse files
authored
feat(core): handle JoinType serde using SCREAMING_SNAKE_CASE and snake_case style (#760)
* use `SCREAMING_SNAKE_CASE` to handle the serde of join type * modifiy for real case tests * cargo fmt and clippy
1 parent 98d2fcf commit a146326

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

wren-modeling-rs/core/src/mdl/builder.rs

+32
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,38 @@ mod test {
430430
assert_eq!(actual, expected)
431431
}
432432

433+
#[test]
434+
fn test_join_type_case_insensitive() {
435+
let case = ["one_to_one", "ONE_TO_ONE"];
436+
let expected = JoinType::OneToOne;
437+
for case in case.iter() {
438+
assert_serde(&format!("\"{}\"", case), expected);
439+
}
440+
441+
let case = ["one_to_many", "ONE_TO_MANY"];
442+
let expected = JoinType::OneToMany;
443+
for case in case.iter() {
444+
assert_serde(&format!("\"{}\"", case), expected);
445+
}
446+
447+
let case = ["many_to_one", "MANY_TO_ONE"];
448+
let expected = JoinType::ManyToOne;
449+
for case in case.iter() {
450+
assert_serde(&format!("\"{}\"", case), expected);
451+
}
452+
453+
let case = ["many_to_many", "MANY_TO_MANY"];
454+
let expected = JoinType::ManyToMany;
455+
for case in case.iter() {
456+
assert_serde(&format!("\"{}\"", case), expected);
457+
}
458+
}
459+
460+
fn assert_serde(json_str: &str, expected: JoinType) {
461+
let actual: JoinType = serde_json::from_str(json_str).unwrap();
462+
assert_eq!(actual, expected);
463+
}
464+
433465
#[test]
434466
fn test_metric_roundtrip() {
435467
let model = MetricBuilder::new("test")

wren-modeling-rs/core/src/mdl/manifest.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,16 @@ pub struct Relationship {
135135
pub properties: BTreeMap<String, String>,
136136
}
137137

138-
// handle case insensitive
139138
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Hash, Clone, Copy)]
140-
#[serde(rename_all = "snake_case")]
139+
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
141140
pub enum JoinType {
141+
#[serde(alias = "one_to_one")]
142142
OneToOne,
143+
#[serde(alias = "one_to_many")]
143144
OneToMany,
145+
#[serde(alias = "many_to_one")]
144146
ManyToOne,
147+
#[serde(alias = "many_to_many")]
145148
ManyToMany,
146149
}
147150

wren-modeling-rs/core/tests/data/mdl.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@
131131
{
132132
"name": "CustomerOrders",
133133
"models": ["customer", "orders"],
134-
"joinType": "one_to_many",
134+
"joinType": "ONE_TO_MANY",
135135
"condition": "customer.custkey = orders.custkey"
136136
},
137137
{
138138
"name" : "CustomerProfile",
139139
"models": ["customer", "profile"],
140-
"joinType": "one_to_one",
140+
"joinType": "ONE_TO_ONE",
141141
"condition": "customer.custkey = profile.custkey"
142142
}
143143
],

0 commit comments

Comments
 (0)