Skip to content

Commit 5e03175

Browse files
authored
Fix nested elements properties validation and add regression test (#97)
* Issue #96 Add test case for nested elements properties bug - Added testNestedElementsPropertiesRejectsAdditionalProperties() to TestRfc8927 - Tests nested elements containing properties schemas with empty properties - Verifies that additional properties are correctly rejected by default - Reproduces the exact failing case found by JtdExhaustiveTest property testing - Schema: {elements:{elements:{properties:{}}}} - Document: [[{},{},[{},{extraProperty:extra-value}]] * Update CI test count for new nested elements test
1 parent 9c555fd commit 5e03175

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
for k in totals: totals[k]+=int(r.get(k,'0'))
4040
except Exception:
4141
pass
42-
exp_tests=465
42+
exp_tests=466
4343
exp_skipped=0
4444
if totals['tests']!=exp_tests or totals['skipped']!=exp_skipped:
4545
print(f"Unexpected test totals: {totals} != expected tests={exp_tests}, skipped={exp_skipped}")

json-java21-jtd/src/test/java/json/java21/jtd/TestRfc8927.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,4 +595,49 @@ public void testDiscriminatorInElementsSchema() throws Exception {
595595
.as("Discriminator in elements schema should validate the property test case")
596596
.isTrue();
597597
}
598+
599+
/// Test case from JtdExhaustiveTest property test failure
600+
/// Nested elements containing properties schemas should reject additional properties
601+
/// Schema: {"elements":{"elements":{"properties":{}}}}
602+
/// Document: [[{},{},[{},{extraProperty":"extra-value"}]]
603+
/// This should fail validation but currently passes incorrectly
604+
@Test
605+
public void testNestedElementsPropertiesRejectsAdditionalProperties() throws Exception {
606+
JsonValue schema = Json.parse("""
607+
{
608+
"elements": {
609+
"elements": {
610+
"properties": {}
611+
}
612+
}
613+
}
614+
""");
615+
JsonValue document = Json.parse("""
616+
[
617+
[{}, {}],
618+
[{}, {"extraProperty": "extra-value"}]
619+
]
620+
""");
621+
622+
LOG.info(() -> "Testing nested elements properties - property test failure case");
623+
LOG.fine(() -> "Schema: " + schema);
624+
LOG.fine(() -> "Document: " + document);
625+
626+
Jtd validator = new Jtd();
627+
Jtd.Result result = validator.validate(schema, document);
628+
629+
LOG.fine(() -> "Validation result: " + (result.isValid() ? "VALID" : "INVALID"));
630+
if (!result.isValid()) {
631+
LOG.fine(() -> "Errors: " + result.errors());
632+
}
633+
634+
// This should fail because the inner object has an extra property
635+
// and the properties schema should reject additional properties by default
636+
assertThat(result.isValid())
637+
.as("Nested elements properties should reject additional properties")
638+
.isFalse();
639+
assertThat(result.errors())
640+
.as("Should have validation errors for additional property")
641+
.isNotEmpty();
642+
}
598643
}

0 commit comments

Comments
 (0)