need to allow empty strings when a string property has a format

This commit is contained in:
2025-07-04 04:23:06 -04:00
parent 710598752f
commit 441597e604
2 changed files with 62 additions and 1 deletions

View File

@ -157,7 +157,11 @@ fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
let errors = format_errors(error_list, &instance_value, schema_id);
// Filter out FALSE_SCHEMA errors if there are other validation errors
let filtered_errors = filter_false_schema_errors(errors);
JsonB(json!({ "errors": filtered_errors }))
if filtered_errors.is_empty() {
JsonB(json!({ "response": "success" }))
} else {
JsonB(json!({ "errors": filtered_errors }))
}
}
}
}
@ -486,6 +490,13 @@ fn handle_additional_items_error(base_path: &str, got: usize) -> Vec<Error> {
}
fn handle_format_error(base_path: &str, want: &str, got: &Cow<Value>, err: &Box<dyn std::error::Error>) -> Vec<Error> {
// If the value is an empty string, skip format validation.
if let Value::String(s) = got.as_ref() {
if s.is_empty() {
return vec![];
}
}
vec![Error {
path: base_path.to_string(),
code: "FORMAT_INVALID".to_string(),