MCPcopy Create free account
hub / github.com/baerwang/openapi-rs / validate_pattern

Function validate_pattern

src/validator/mod.rs:1038–1061  ·  view source on GitHub ↗
(key: &str, value: &Value, pattern: Option<&String>)

Source from the content-addressed store, hash-verified

1036}
1037
1038fn validate_pattern(key: &str, value: &Value, pattern: Option<&String>) -> Result<()> {
1039 if let Some(pattern_str) = pattern {
1040 if let Some(str_val) = value.as_str() {
1041 let regex = Regex::new(pattern_str).map_err(|e| {
1042 anyhow!(
1043 "Invalid regex pattern '{}' for field '{}': {}",
1044 pattern_str,
1045 key,
1046 e
1047 )
1048 })?;
1049
1050 if !regex.is_match(str_val) {
1051 return Err(anyhow!(
1052 "Value '{}' for field '{}' does not match the required pattern '{}'",
1053 str_val,
1054 key,
1055 pattern_str
1056 ));
1057 }
1058 }
1059 }
1060 Ok(())
1061}

Callers 4

queryFunction · 0.85
validate_propertiesFunction · 0.85

Calls

no outgoing calls