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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#[allow(unused_imports)] use log::*;
use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
pub mod content_types;
pub mod bodies;
#[cfg_attr(feature = "ffi", repr(C))]
#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize, Serialize)]
#[allow(non_camel_case_types)]
pub enum PactSpecification {
Unknown,
V1,
V1_1,
V2,
V3,
V4
}
impl Default for PactSpecification {
fn default() -> Self {
PactSpecification::Unknown
}
}
impl PactSpecification {
pub fn version_str(&self) -> String {
match *self {
PactSpecification::V1 => "1.0.0",
PactSpecification::V1_1 => "1.1.0",
PactSpecification::V2 => "2.0.0",
PactSpecification::V3 => "3.0.0",
PactSpecification::V4 => "4.0",
_ => "unknown"
}.into()
}
pub fn to_string(&self) -> String {
match *self {
PactSpecification::V1 => "V1",
PactSpecification::V1_1 => "V1.1",
PactSpecification::V2 => "V2",
PactSpecification::V3 => "V3",
PactSpecification::V4 => "V4",
_ => "unknown"
}.into()
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
pub struct Consumer {
pub name: String
}
impl Consumer {
pub fn from_json(pact_json: &Value) -> Consumer {
let val = match pact_json.get("name") {
Some(v) => match v.clone() {
Value::String(s) => s,
_ => v.to_string()
},
None => "consumer".to_string()
};
Consumer { name: val.clone() }
}
pub fn to_json(&self) -> Value {
json!({ "name" : self.name })
}
}
#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq)]
pub struct Provider {
pub name: String
}
impl Provider {
pub fn from_json(pact_json: &Value) -> Provider {
let val = match pact_json.get("name") {
Some(v) => match v.clone() {
Value::String(s) => s,
_ => v.to_string()
},
None => "provider".to_string()
};
Provider { name: val.clone() }
}
pub fn to_json(&self) -> Value {
json!({ "name" : self.name })
}
}
#[cfg(test)]
mod tests;