unevaluatedProperties now cascade infinitely down their leaf when strict validation mode is on
This commit is contained in:
@ -308,7 +308,7 @@ fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
_ => None,
|
||||
};
|
||||
|
||||
match cache.schemas.validate(&instance_value, schema.index, options.as_ref()) {
|
||||
match cache.schemas.validate(&instance_value, schema.index, options) {
|
||||
Ok(_) => {
|
||||
let mut custom_errors = Vec::new();
|
||||
if schema.t == SchemaType::Type || schema.t == SchemaType::PublicPunc || schema.t == SchemaType::PrivatePunc {
|
||||
|
||||
@ -355,7 +355,16 @@ pub fn additional_properties_schemas() -> JsonB {
|
||||
|
||||
pub fn unevaluated_properties_schemas() -> JsonB {
|
||||
let enums = json!([]);
|
||||
let types = json!([]);
|
||||
let types = json!([{
|
||||
"name": "nested_for_uneval",
|
||||
"schemas": [{
|
||||
"$id": "nested_for_uneval",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"deep_prop": { "type": "string" }
|
||||
}
|
||||
}]
|
||||
}]);
|
||||
let puncs = json!([
|
||||
{
|
||||
"name": "simple_unevaluated_test",
|
||||
@ -396,6 +405,29 @@ pub fn unevaluated_properties_schemas() -> JsonB {
|
||||
},
|
||||
"unevaluatedProperties": false
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "nested_unevaluated_test",
|
||||
"public": true, // To trigger strict mode
|
||||
"schemas": [{
|
||||
"$id": "nested_unevaluated_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"non_strict_branch": {
|
||||
"type": "object",
|
||||
"unevaluatedProperties": true, // The magic switch
|
||||
"properties": {
|
||||
"some_prop": { "$ref": "nested_for_uneval" }
|
||||
}
|
||||
},
|
||||
"strict_branch": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"another_prop": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
]);
|
||||
|
||||
|
||||
27
src/tests.rs
27
src/tests.rs
@ -452,6 +452,33 @@ fn test_validate_unevaluated_properties() {
|
||||
|
||||
let valid_result = validate_json_schema("simple_unevaluated_test.request", jsonb(valid_instance));
|
||||
assert_success(&valid_result);
|
||||
|
||||
// Test 4: Test that unevaluatedProperties: true cascades down refs
|
||||
let cascading_instance = json!({
|
||||
"strict_branch": {
|
||||
"another_prop": "is_ok"
|
||||
},
|
||||
"non_strict_branch": {
|
||||
"extra_at_toplevel": "is_ok", // Extra property at this level
|
||||
"some_prop": {
|
||||
"deep_prop": "is_ok",
|
||||
"extra_in_ref": "is_also_ok" // Extra property in the $ref'd schema
|
||||
}
|
||||
}
|
||||
});
|
||||
let cascading_result = validate_json_schema("nested_unevaluated_test.request", jsonb(cascading_instance));
|
||||
assert_success(&cascading_result);
|
||||
|
||||
// Test 5: For good measure, test that the strict branch is still strict
|
||||
let strict_fail_instance = json!({
|
||||
"strict_branch": {
|
||||
"another_prop": "is_ok",
|
||||
"extra_in_strict": "is_not_ok"
|
||||
}
|
||||
});
|
||||
let strict_fail_result = validate_json_schema("nested_unevaluated_test.request", jsonb(strict_fail_instance));
|
||||
assert_error_count(&strict_fail_result, 1);
|
||||
assert_has_error(&strict_fail_result, "ADDITIONAL_PROPERTIES_NOT_ALLOWED", "/strict_branch/extra_in_strict");
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
|
||||
Reference in New Issue
Block a user