Skip to content

Commit

Permalink
fix issue in patternproperties not evaluate all schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-toepfer committed Oct 9, 2023
1 parent 92a6488 commit 10cb800
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,9 @@ private boolean propertyMatches(final Map.Entry<String, JsonValue> property) {
.entrySet()
.stream()
.filter(e -> e.getKey().matcher(property.getKey()).find())
.findFirst()
.map(Map.Entry::getValue)
.map(JsonSchemas::load)
.map(schema -> schema.validator().validate(property.getValue()).isEmpty())
.orElse(true);
.allMatch(schema -> schema.validator().validate(property.getValue()).isEmpty());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ void should_be_invalid_if_properties_not_applies_to_his_schema() {
);
}

/*
Attention can be falky.
JsonObject is a map, so the properties occurred in random order.
This means for this test it could be green without using all assertions.
*/
@Test
void should_be_invalid_if_one_schema_doesn_apply() {
assertThat(
new PatternPropertiesKeywordType()
.createKeyword(
new DefaultJsonSchemaFactory().create(JsonValue.TRUE),
Json.createObjectBuilder().add("t.st", JsonValue.TRUE).add("t.*", JsonValue.FALSE).build()
)
.asApplicator()
.applyTo(Json.createObjectBuilder().add("test", 1).build()),
is(false)
);
}

@Test
void should_be_valid_if_properties_not_covered() {
assertThat(
Expand Down

0 comments on commit 10cb800

Please sign in to comment.