Skip to content

Commit

Permalink
add basic email parsing regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sky-2002 committed Dec 18, 2024
1 parent 241a53b commit 283f63c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/json_schema/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
// 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<String> {
// JSON Schema Spec: Empty object means unconstrained, any json type is legal
let types = vec![
Expand Down

0 comments on commit 283f63c

Please sign in to comment.