From abbf40fc2e7484591efa3def26094ae5c3722c00 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 7 Nov 2018 12:55:33 +0100 Subject: [PATCH] define a separate enum ApiStringFormat --- src/json_schema.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/json_schema.rs b/src/json_schema.rs index 14e07b3f..982cc66b 100644 --- a/src/json_schema.rs +++ b/src/json_schema.rs @@ -29,7 +29,7 @@ pub struct JssString { pub default: Option<&'static str>, pub min_length: Option, pub max_length: Option, - pub pattern: Option, + pub format: ApiStringFormat, } #[derive(Debug)] @@ -91,9 +91,16 @@ pub const DEFAULTSTRING: JssString = JssString { default: None, min_length: None, max_length: None, - pattern: None, + format: ApiStringFormat::None, }; +#[derive(Debug)] +pub enum ApiStringFormat { + None, + Pattern(Regex), + Complex(Box), +} + #[macro_export] macro_rules! ApiString { ($($name:ident => $e:expr),*) => {{ @@ -168,7 +175,7 @@ fn parse_simple_value(value_str: &str, schema: &Jss) -> Result { } } - if let Some(ref regex) = jss_string.pattern { + if let ApiStringFormat::Pattern(ref regex) = jss_string.format { if !regex.is_match(&res) { bail!("value does not match the regex pattern"); } @@ -332,7 +339,7 @@ fn test_query_string() { let schema = parameter!{name => ApiString!{ optional => false, - pattern => Some(Regex::new("test").unwrap()) + format => ApiStringFormat::Pattern(Regex::new("test").unwrap()) }}; let res = parse_query_string("name=abcd", &schema, true); @@ -343,7 +350,7 @@ fn test_query_string() { let schema = parameter!{name => ApiString!{ optional => false, - pattern => Some(Regex::new("^test$").unwrap()) + format => ApiStringFormat::Pattern(Regex::new("^test$").unwrap()) }}; let res = parse_query_string("name=ateststring", &schema, true);