Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate mapping super types #923

Merged
merged 1 commit into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int getSuperTypeCount() {
return superTypes.length;
}

ConfigMappingInterface[] getSuperTypes() {
public ConfigMappingInterface[] getSuperTypes() {
return superTypes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ default void validateMappingInterface(
final Object mappingObject,
final List<Problem> problems) {

for (ConfigMappingInterface superType : mappingInterface.getSuperTypes()) {
for (Property property : superType.getProperties()) {
validateProperty(property, currentPath, namingStrategy, mappingObject, false, problems);
}
}

for (Property property : mappingInterface.getProperties()) {
validateProperty(property, currentPath, namingStrategy, mappingObject, false, problems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,34 @@ interface Nested {
}
}

@Test
void hierarchy() {
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withValidator(new BeanValidationConfigValidatorImpl())
.withMapping(Child.class)
.withSources(config("validator.child.number", "1"))
.build();

ConfigValidationException validationException = assertThrows(ConfigValidationException.class,
() -> config.getConfigMapping(Child.class));
List<String> validations = new ArrayList<>();
for (int i = 0; i < validationException.getProblemCount(); i++) {
validations.add(validationException.getProblem(i).getMessage());
}
assertEquals(1, validations.size());
assertTrue(validations.contains("validator.child.number must be greater than or equal to 10"));
}

public interface Parent {
@Min(10)
Integer number();
}

@ConfigMapping(prefix = "validator.child")
public interface Child extends Parent {

}

private static void assertValidationsEqual(List<String> validations, String... expectedProblemMessages) {
List<String> remainingActual = new ArrayList<>(validations);
List<String> remainingExpected = Stream.of(expectedProblemMessages).collect(Collectors.toList());
Expand Down