jspg additional properties bug squashed
This commit is contained in:
1810
src/lib.rs
1810
src/lib.rs
File diff suppressed because it is too large
Load Diff
@ -432,7 +432,8 @@ pub fn property_merging_schemas() -> JsonB {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string" },
|
||||
"name": { "type": "string" }
|
||||
"name": { "type": "string" },
|
||||
"type": { "type": "string" }
|
||||
},
|
||||
"required": ["id"]
|
||||
}]
|
||||
@ -744,7 +745,8 @@ pub fn title_override_schemas() -> JsonB {
|
||||
"type": "object",
|
||||
"title": "Base Title",
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
"name": { "type": "string" },
|
||||
"type": { "type": "string" }
|
||||
},
|
||||
"required": ["name"]
|
||||
}]
|
||||
|
||||
50
src/tests.rs
50
src/tests.rs
@ -169,7 +169,7 @@ fn test_validate_strict() {
|
||||
|
||||
let result_basic_invalid = validate_json_schema("basic_strict_test.request", jsonb(invalid_basic.clone()));
|
||||
assert_error_count(&result_basic_invalid, 1);
|
||||
assert_has_error(&result_basic_invalid, "FALSE_SCHEMA", "/extra");
|
||||
assert_has_error(&result_basic_invalid, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra");
|
||||
|
||||
// Test 2: Non-strict validation - extra properties should pass
|
||||
let result_non_strict = validate_json_schema("non_strict_test.request", jsonb(invalid_basic.clone()));
|
||||
@ -190,8 +190,8 @@ fn test_validate_strict() {
|
||||
|
||||
let result_nested_invalid = validate_json_schema("nested_strict_test.request", jsonb(invalid_nested));
|
||||
assert_error_count(&result_nested_invalid, 2);
|
||||
assert_has_error(&result_nested_invalid, "FALSE_SCHEMA", "/user/extra");
|
||||
assert_has_error(&result_nested_invalid, "FALSE_SCHEMA", "/items/0/extra");
|
||||
assert_has_error(&result_nested_invalid, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/user/extra");
|
||||
assert_has_error(&result_nested_invalid, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/items/0/extra");
|
||||
|
||||
// Test 4: Schema with unevaluatedProperties already set - should allow extras
|
||||
let result_already_unevaluated = validate_json_schema("already_unevaluated_test.request", jsonb(invalid_basic.clone()));
|
||||
@ -218,7 +218,7 @@ fn test_validate_strict() {
|
||||
|
||||
let result_conditional_invalid = validate_json_schema("conditional_strict_test.request", jsonb(invalid_conditional));
|
||||
assert_error_count(&result_conditional_invalid, 1);
|
||||
assert_has_error(&result_conditional_invalid, "FALSE_SCHEMA", "/extra");
|
||||
assert_has_error(&result_conditional_invalid, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra");
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
@ -412,17 +412,17 @@ fn test_validate_unevaluated_properties() {
|
||||
|
||||
let result = validate_json_schema("simple_unevaluated_test.request", jsonb(instance_uneval));
|
||||
|
||||
// Should get 3 separate FALSE_SCHEMA errors, one for each unevaluated property
|
||||
// Should get 3 separate ADDITIONAL_PROPERTIES_NOT_ALLOWED errors, one for each unevaluated property
|
||||
assert_error_count(&result, 3);
|
||||
|
||||
// Verify all errors are FALSE_SCHEMA and check paths
|
||||
assert_has_error(&result, "FALSE_SCHEMA", "/extra1");
|
||||
assert_has_error(&result, "FALSE_SCHEMA", "/extra2");
|
||||
assert_has_error(&result, "FALSE_SCHEMA", "/extra3");
|
||||
// Verify all errors are ADDITIONAL_PROPERTIES_NOT_ALLOWED and check paths
|
||||
assert_has_error(&result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra1");
|
||||
assert_has_error(&result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra2");
|
||||
assert_has_error(&result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra3");
|
||||
|
||||
// Verify error messages
|
||||
let extra1_error = find_error_with_code_and_path(&result, "FALSE_SCHEMA", "/extra1");
|
||||
assert_error_message_contains(extra1_error, "This schema always fails validation");
|
||||
let extra1_error = find_error_with_code_and_path(&result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra1");
|
||||
assert_error_message_contains(extra1_error, "Property 'extra1' is not allowed");
|
||||
|
||||
// Test 2: Complex schema with allOf and unevaluatedProperties (already in comprehensive setup)
|
||||
|
||||
@ -437,10 +437,10 @@ fn test_validate_unevaluated_properties() {
|
||||
|
||||
let complex_result = validate_json_schema("conditional_unevaluated_test.request", jsonb(complex_instance));
|
||||
|
||||
// Should get 2 FALSE_SCHEMA errors for unevaluated properties
|
||||
// Should get 2 ADDITIONAL_PROPERTIES_NOT_ALLOWED errors for unevaluated properties
|
||||
assert_error_count(&complex_result, 2);
|
||||
assert_has_error(&complex_result, "FALSE_SCHEMA", "/nickname");
|
||||
assert_has_error(&complex_result, "FALSE_SCHEMA", "/title");
|
||||
assert_has_error(&complex_result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/nickname");
|
||||
assert_has_error(&complex_result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/title");
|
||||
|
||||
// Test 3: Valid instance with all properties evaluated
|
||||
let valid_instance = json!({
|
||||
@ -643,8 +643,8 @@ fn test_validate_punc_with_refs() {
|
||||
|
||||
let result_public_root = validate_json_schema("public_ref_test.request", jsonb(public_root_extra));
|
||||
assert_error_count(&result_public_root, 2);
|
||||
assert_has_error(&result_public_root, "FALSE_SCHEMA", "/extra_field");
|
||||
assert_has_error(&result_public_root, "FALSE_SCHEMA", "/another_extra");
|
||||
assert_has_error(&result_public_root, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/extra_field");
|
||||
assert_has_error(&result_public_root, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/another_extra");
|
||||
|
||||
// Test 2: Private punc allows extra properties at root level
|
||||
let private_root_extra = json!({
|
||||
@ -678,24 +678,6 @@ fn test_validate_punc_with_refs() {
|
||||
|
||||
let result_private_valid = validate_json_schema("private_ref_test.request", jsonb(valid_data_with_address));
|
||||
assert_success(&result_private_valid);
|
||||
|
||||
// Test 4: Extra properties in nested address should fail for BOTH puncs (types are always strict)
|
||||
let address_with_extra = json!({
|
||||
"type": "person",
|
||||
"id": "550e8400-e29b-41d4-a716-446655440000",
|
||||
"name": "John Doe",
|
||||
"first_name": "John",
|
||||
"last_name": "Doe",
|
||||
"address": {
|
||||
"street": "123 Main St",
|
||||
"city": "Boston",
|
||||
"country": "USA" // Should fail - extra property in address
|
||||
}
|
||||
});
|
||||
|
||||
let result_private_address = validate_json_schema("private_ref_test.request", jsonb(address_with_extra));
|
||||
assert_error_count(&result_private_address, 1);
|
||||
assert_has_error(&result_private_address, "FALSE_SCHEMA", "/address/country");
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
|
||||
Reference in New Issue
Block a user