Skip to content

Commit

Permalink
SD-1761 T&T eventID uniqueness check now also working when some but n…
Browse files Browse the repository at this point in the history
…ot all events have an eventID
  • Loading branch information
gj0dcsa committed Nov 20, 2024
1 parent a679f6c commit 4a1d469
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
Expand All @@ -38,19 +39,17 @@ public static ActionCheck responseContentChecks(UUID matched, String standardVer

var checks = new ArrayList<JsonContentCheck>();

checks.add(JsonAttribute.customValidator(
"Validate that eventID values are unique",
body -> {
Set<String> uniqueEventIds = StreamSupport.stream(body.spliterator(), false)
.filter(node -> node.has("eventID"))
.map(node -> node.path("eventID").asText())
.collect(Collectors.toSet());
if (!uniqueEventIds.isEmpty() && uniqueEventIds.size() != body.size()) {
return Set.of("Event ID values are not unique");
}
return Set.of();
}
));
// The OpenAPI specification explicitly states that the eventIDs must be unique.
checks.add(
JsonAttribute.customValidator(
"Validate that eventID values are unique",
body ->
StreamSupport.stream(body.spliterator(), false)
.filter(node -> node.has("eventID"))
.map(node -> node.path("eventID").asText())
.allMatch(new HashSet<>()::add)
? Set.of()
: Set.of("Event ID values are not unique")));

checks.add(JsonAttribute.customValidator(
"Validate eventCreatedDateTime parameter conditions are met",
Expand Down

0 comments on commit 4a1d469

Please sign in to comment.