Skip to content

Commit

Permalink
Take into account container element constraints in config mapping val…
Browse files Browse the repository at this point in the history
…idation

Fixes quarkusio#35081
  • Loading branch information
gsmet committed Jul 28, 2023
1 parent 6629767 commit 2e75e4c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ void configValidator(
if (configMappings.contains(declaringClass.name())) {
configMappingsConstraints.add(builtinConstraintCandidate);
}
} else if (annotation.target().kind() == AnnotationTarget.Kind.TYPE) {
AnnotationTarget target = annotation.target().asType().enclosingTarget();
if (target.kind() == AnnotationTarget.Kind.METHOD) {
MethodInfo methodInfo = target.asMethod();
ClassInfo declaringClass = methodInfo.declaringClass();
if (configMappings.contains(declaringClass.name())) {
configMappingsConstraints.add(builtinConstraintCandidate);
}
}
} else if (annotation.target().kind() == AnnotationTarget.Kind.CLASS) {
ClassInfo classInfo = annotation.target().asClass();
if (configMappings.contains(classInfo.name())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.List;

import jakarta.inject.Inject;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;

import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -25,6 +28,7 @@ public class ConfigMappingInvalidTest {
static final QuarkusUnitTest UNIT_TEST = new QuarkusUnitTest().setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(new StringAsset("validator.server.host=localhost\n" +
"validator.server.services=redis,postgresql\n" +
"validator.hierarchy.number=1\n" +
"validator.repeatable.name=a"), "application.properties"));

Expand Down Expand Up @@ -54,6 +58,8 @@ void repeatable() {
public interface Server {
@Max(3)
String host();

List<@NotEmpty String> services();
}

public interface Parent {
Expand Down

0 comments on commit 2e75e4c

Please sign in to comment.