summaryrefslogtreecommitdiff
path: root/src/val.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/val.rs')
-rw-r--r--src/val.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/val.rs b/src/val.rs
new file mode 100644
index 0000000..6cc7dfe
--- /dev/null
+++ b/src/val.rs
@@ -0,0 +1,37 @@
+mod validator;
+
+use serde::{Serialize, Deserialize};
+use serde_json;
+
+use validator::Validator;
+
+#[derive(Deserialize, Serialize)]
+struct Profile {
+ tg_id: i32,
+ fullname: String,
+ username: String,
+ is_admin: bool,
+ is_hidden: bool
+}
+
+
+fn test_validation() -> Result<(), String> {
+ let profile = Profile {
+ tg_id: 123,
+ fullname: String::from("Andrew Guschin"),
+ username: String::from("guschin"),
+ is_admin: true,
+ is_hidden: false
+ };
+
+ let request_data = serde_json::to_string(&profile).unwrap();
+
+ let validator = match Validator::from_file("src/schema.json") {
+ Ok(val) => val,
+ Err(msg) => return Err(msg)
+ };
+ let result = validator.check(&request_data);
+ println!("Is valid: {}", result);
+
+ return Ok(());
+}