Skip to content

Commit

Permalink
Fix validation constraint scan, remove unnecessary anno target check (#…
Browse files Browse the repository at this point in the history
…2042)

Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Oct 30, 2024
1 parent 93d70a5 commit 4bd0e68
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.smallrye.openapi.api.constants.KotlinConstants;
import io.smallrye.openapi.internal.models.media.SchemaSupport;
import io.smallrye.openapi.runtime.scanner.spi.AnnotationScannerContext;
import io.smallrye.openapi.runtime.util.JandexUtil;

/**
* @author Michael Edgar {@literal <[email protected]>}
Expand Down Expand Up @@ -560,7 +559,7 @@ boolean allowsAdditionalProperties(Schema schema) {
AnnotationInstance getConstraint(AnnotationTarget target, List<DotName> annotationName) {
AnnotationInstance constraint = context.annotations().getAnnotation(target, annotationName);

if (constraint != null && JandexUtil.equals(constraint.target(), target)) {
if (constraint != null) {
AnnotationValue groupValue = constraint.value("groups");

if (groupValue == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;
import java.util.Optional;
import java.util.OptionalDouble;
Expand Down Expand Up @@ -597,4 +602,39 @@ public Fruit get(@jakarta.ws.rs.PathParam("fruitId") FruitId fruitId) {
void testPathParamValueType() throws IOException, JSONException {
test("params.value-class-pathparam.json", Issue1466.CLASSES);
}

static class ParameterConstraintComposition {
static final Class<?>[] CLASSES = {
Resource.class,
CustomIntConstraint.class
};

@jakarta.validation.constraints.Min(0)
@jakarta.validation.constraints.Max(100000)
@jakarta.validation.Constraint(validatedBy = {})
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface CustomIntConstraint {
String message() default "";

Class<?>[] groups() default {};

Class<? extends jakarta.validation.Payload>[] payload() default {};
}

@jakarta.ws.rs.Path("/custom-resource")
static class Resource {
@jakarta.ws.rs.GET
@jakarta.ws.rs.Path("{id}")
public String get(@CustomIntConstraint @jakarta.ws.rs.QueryParam("id") int id) {
return null;
}
}
}

@Test
void testParameterConstraintComposition() throws IOException, JSONException {
test("params.constraint-composition.json", ParameterConstraintComposition.CLASSES);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"openapi" : "3.1.0",
"paths" : {
"/custom-resource/{id}" : {
"get" : {
"parameters" : [ {
"name" : "id",
"in" : "query",
"schema" : {
"type" : "integer",
"format" : "int32",
"maximum" : 100000,
"minimum" : 0
}
} ],
"responses" : {
"200" : {
"description" : "OK",
"content" : {
"*/*" : {
"schema" : {
"type" : "string"
}
}
}
}
}
}
}
}
}

0 comments on commit 4bd0e68

Please sign in to comment.