From 283f63c726f7ca5a6cc5b0b0fe42ab01e4a8c2d1 Mon Sep 17 00:00:00 2001 From: Aakash Thatte Date: Wed, 18 Dec 2024 22:26:44 +0530 Subject: [PATCH] add basic email parsing regex --- src/json_schema/parsing.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/json_schema/parsing.rs b/src/json_schema/parsing.rs index 9ac373b..a36702f 100644 --- a/src/json_schema/parsing.rs +++ b/src/json_schema/parsing.rs @@ -61,12 +61,19 @@ impl<'a> Parser<'a> { Value::Object(obj) if obj.contains_key("const") => self.parse_const(obj), Value::Object(obj) if obj.contains_key("$ref") => self.parse_ref(obj), Value::Object(obj) if obj.contains_key("type") => self.parse_type(obj), + Value::Object(obj) if obj.contains_key("format") && obj["format"] == "email" => self.parse_email(), json => Err(JsonSchemaParserError::UnsupportedJsonSchema(Box::new( json.clone(), ))), } } + pub fn parse_email(&self) -> Result { + // A common email regex pattern + let regex_pattern = r"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"; + Ok(regex_pattern.to_string()) + } + fn parse_empty_object(&mut self) -> Result { // JSON Schema Spec: Empty object means unconstrained, any json type is legal let types = vec![