Skip to content

Commit

Permalink
Add unevaluatedProperties test (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay committed Feb 14, 2024
1 parent 1f60740 commit 7cda40e
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,57 @@ void annotationsOnlyDroppedAtTheEndOfSchemaProcessing() {
assertEquals("unevaluatedProperties", assertions.get(1).getType());
assertEquals("key4", assertions.get(1).getProperty());
}

/**
* Issue 967.
*/
@Test
void subschemaProcessing() {
String schemaData = "{\r\n"
+ " \"$schema\": \"https://json-schema.org/draft/2019-09/schema\",\r\n"
+ " \"$defs\" : {\r\n"
+ " \"subschema\": {\r\n"
+ " \"type\": \"object\",\r\n"
+ " \"required\": [\"group\"],\r\n"
+ " \"properties\": {\r\n"
+ " \"group\": {\r\n"
+ " \"type\": \"object\",\r\n"
+ " \"additionalProperties\": false,\r\n"
+ " \"required\": [\"parentprop\"],\r\n"
+ " \"properties\": {\r\n"
+ " \"parentprop\": {\r\n"
+ " \"type\": \"string\"\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n"
+ " }\r\n"
+ " },\r\n"
+ " \"type\": \"object\",\r\n"
+ " \"unevaluatedProperties\": false,\r\n"
+ " \"allOf\": [\r\n"
+ " {\"properties\": { \"group\" : {\"type\":\"object\"} } },\r\n"
+ " {\"$ref\": \"#/$defs/subschema\"}\r\n"
+ " ],\r\n"
+ " \"required\": [\"childprop\"],\r\n"
+ " \"properties\": {\r\n"
+ " \"childprop\": {\r\n"
+ " \"type\": \"string\"\r\n"
+ " }\r\n"
+ " }\r\n"
+ "}";
String inputData = "{\r\n"
+ " \"childprop\": \"something\",\r\n"
+ " \"group\": {\r\n"
+ " \"parentprop\":\"something\",\r\n"
+ " \"notallowed\": false\r\n"
+ " }\r\n"
+ "}";
JsonSchema schema = JsonSchemaFactory.getInstance(VersionFlag.V201909).getSchema(schemaData);
Set<ValidationMessage> messages = schema.validate(inputData, InputFormat.JSON);
assertEquals(1, messages.size());
List<ValidationMessage> assertions = messages.stream().collect(Collectors.toList());
assertEquals("additionalProperties", assertions.get(0).getType());
assertEquals("notallowed", assertions.get(0).getProperty());
}
}

0 comments on commit 7cda40e

Please sign in to comment.