Skip to content

Commit 16eef74

Browse files
committed
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}]]
1 parent d607df1 commit 16eef74

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

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)