Skip to content

Commit

Permalink
Added error logs on validation failures
Browse files Browse the repository at this point in the history
  • Loading branch information
koushikr committed Sep 10, 2024
1 parent 6b34b98 commit d8a71e5
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

@UtilityClass
@Slf4j
Expand All @@ -33,9 +34,13 @@ public static boolean valid(final SchemaDetails schemaDetails,
final Class<?> klass) {
final var fields = getAllFields(klass);
final var validationType = schemaDetails.getValidationType();
final var allAttributesListed = fields.stream().allMatch(each -> schemaDetails.hasAttribute(each.getName()));
if (!allAttributesListed && validationType == SchemaValidationType.STRICT) {
log.debug("There seems to attributes present in the class definition that are not in the schema. [Validation Failed]");
final var allAttributesListed = fields.stream().filter(each -> schemaDetails.hasAttribute(each.getName()))
.collect(Collectors.toSet());
if (!allAttributesListed.isEmpty() &&
validationType == SchemaValidationType.STRICT) {
log.error("There seems to be attributes present in the class definition that are not in the schema. " +
"[Validation Failed]. The extra attributes are {}",
allAttributesListed);
return false;
}
return schemaDetails.getAttributes().stream().allMatch(each ->
Expand Down

0 comments on commit d8a71e5

Please sign in to comment.