Skip to content

Commit

Permalink
Ignore framework-specific Context types for use as request body (#1364)
Browse files Browse the repository at this point in the history
Fixes #1363

Signed-off-by: Michael Edgar <michael@xlate.io>
  • Loading branch information
MikeEdgar authored Jan 31, 2023
1 parent bedc194 commit 32168ea
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ default Type getRequestBodyParameterClassType(final AnnotationScannerContext con

return IntStream.range(0, methodParams.size())
.filter(position -> !isKotlinContinuation(methodParams.get(position)))
.filter(position -> !isFrameworkContextType(methodParams.get(position)))
.filter(position -> !isPathParameter(context, method.parameterName(position), params))
.filter(position -> {
List<AnnotationInstance> annotations = JandexUtil.getParameterAnnotations(method, (short) position);
Expand Down Expand Up @@ -1066,6 +1067,20 @@ default boolean isPathParameter(final AnnotationScannerContext context, String n
return false;
}

/**
* Determines whether the given type is a special "context" type of the current
* web/REST framework and should not be considered as a request body type.
*
* This method should be overridden by framework-specific annotation scanners.
*
* @param type the type to consider
*
* @return true if the type is a framework-specific special/context type, otherwise false.
*/
default boolean isFrameworkContextType(Type type) {
return false;
}

/**
* Get the default description for a HTTP Status code
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public boolean isMultipartInput(Type inputType) {
return RestEasyConstants.MULTIPART_INPUTS.contains(inputType.name());
}

@Override
public boolean isFrameworkContextType(Type type) {
return JaxRsConstants.CONTEXTS.contains(type.name());
}

@Override
public boolean containsScannerAnnotations(List<AnnotationInstance> instances,
List<AnnotationScannerExtension> extensions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jboss.jandex.DotName;

Expand Down Expand Up @@ -92,6 +94,14 @@ public class JaxRsConstants {
static final Set<DotName> PATCH = new TreeSet<>(Arrays.asList(
DotName.createSimple("javax.ws.rs.PATCH"),
DotName.createSimple("jakarta.ws.rs.PATCH")));
static final Set<DotName> CONTEXTS = Stream.of("javax", "jakarta")
.map(prefix -> DotName.createComponentized(null, prefix))
.map(prefix -> DotName.createComponentized(prefix, "ws"))
.map(prefix -> DotName.createComponentized(prefix, "rs"))
.map(prefix -> DotName.createComponentized(prefix, "core"))
.flatMap(prefix -> Stream.of("Application", "UriInfo", "Request", "HttpHeaders", "SecurityContext")
.map(simpleName -> DotName.createComponentized(prefix, simpleName)))
.collect(Collectors.toSet());

static final String TO_RESPONSE_METHOD_NAME = "toResponse";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ void testJakartaResteasyMultipartInputList() throws IOException, JSONException {
@Test
void testJavaxResteasyMultipartFormDataInput() throws IOException, JSONException {
test("params.resteasy-multipart-form-data-input.json",
javax.ws.rs.core.HttpHeaders.class,
test.io.smallrye.openapi.runtime.scanner.javax.ResteasyMultipartFormDataInputTestResource.class);
}

@Test
void testJakartaResteasyMultipartFormDataInput() throws IOException, JSONException {
test("params.resteasy-multipart-form-data-input.json",
jakarta.ws.rs.core.HttpHeaders.class,
test.io.smallrye.openapi.runtime.scanner.jakarta.ResteasyMultipartFormDataInputTestResource.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
Expand All @@ -14,7 +15,7 @@ public class ResteasyMultipartFormDataInputTestResource {
@Path(value = "post")
@Consumes(value = MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings(value = "unused")
public void post(MultipartFormDataInput input) {
public void post(HttpHeaders headers, MultipartFormDataInput input) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
Expand All @@ -14,7 +15,7 @@ public class ResteasyMultipartFormDataInputTestResource {
@Path(value = "post")
@Consumes(value = MediaType.MULTIPART_FORM_DATA)
@SuppressWarnings(value = "unused")
public void post(MultipartFormDataInput input) {
public void post(HttpHeaders headers, MultipartFormDataInput input) {
}

}

0 comments on commit 32168ea

Please sign in to comment.