need to allow empty strings when a string property has a format
This commit is contained in:
50
src/tests.rs
50
src/tests.rs
@ -1237,3 +1237,53 @@ fn test_unevaluated_properties_errors() {
|
||||
let valid_result = validate_json_schema(schema_id, jsonb(valid_instance));
|
||||
assert_success_with_json!(valid_result, "All properties are evaluated, should pass");
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
fn test_format_validation_allows_empty_string() {
|
||||
clear_json_schemas();
|
||||
let schema_id = "format_schema_empty";
|
||||
let schema = json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"uuid": { "type": "string", "format": "uuid" },
|
||||
"date_time": { "type": "string", "format": "date-time" },
|
||||
"email": { "type": "string", "format": "email" }
|
||||
}
|
||||
});
|
||||
|
||||
let _ = cache_json_schema(schema_id, jsonb(schema), false);
|
||||
|
||||
// Test with empty strings for all formatted fields
|
||||
let instance = json!({
|
||||
"uuid": "",
|
||||
"date_time": "",
|
||||
"email": ""
|
||||
});
|
||||
|
||||
let result = validate_json_schema(schema_id, jsonb(instance));
|
||||
|
||||
// This is the test that should fail before the change and pass after
|
||||
assert_success_with_json!(result, "Empty strings should be allowed for format validation");
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
fn test_non_empty_string_format_validation_still_fails() {
|
||||
clear_json_schemas();
|
||||
let schema_id = "non_empty_fail_schema";
|
||||
let schema = json!({
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"date_time": { "type": "string", "format": "date-time" }
|
||||
}
|
||||
});
|
||||
|
||||
let _ = cache_json_schema(schema_id, jsonb(schema), false);
|
||||
|
||||
// A non-empty but invalid string should still fail
|
||||
let instance = json!({
|
||||
"date_time": "not-a-date"
|
||||
});
|
||||
|
||||
let result = validate_json_schema(schema_id, jsonb(instance));
|
||||
assert_failure_with_json!(result, 1, "Value \"not-a-date\" is not a valid date-time format");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user