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

Take into account container element constraints in config mapping validation #35087

Merged
merged 1 commit into from
Jul 28, 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 @@ -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