-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Allow not JAX-RS parameters within resource methods #40031
Merged
geoand
merged 1 commit into
quarkusio:main
from
poldinik:draft-of-resteasy-params-skip-filter
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
.../quarkus/resteasy/reactive/server/test/resource/basic/AllowNotResteasyParametersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.quarkus.resteasy.reactive.server.test.resource.basic; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import java.util.function.Consumer; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.builder.BuildContext; | ||
import io.quarkus.builder.BuildStep; | ||
import io.quarkus.resteasy.reactive.server.spi.AllowNotRestParametersBuildItem; | ||
import io.quarkus.resteasy.reactive.server.test.resource.basic.resource.MixedParameterResource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
/** | ||
* @tpSubChapter Resources | ||
* @tpChapter Integration tests | ||
* @tpTestCaseDetails Test resources with not all method parameters related to RESTEasy. | ||
*/ | ||
@DisplayName("Allow Not RESTEasy Method Parameters") | ||
public class AllowNotResteasyParametersTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest quarkusUnitTest = new QuarkusUnitTest() | ||
.addBuildChainCustomizer(new Consumer<BuildChainBuilder>() { | ||
@Override | ||
public void accept(BuildChainBuilder buildChainBuilder) { | ||
buildChainBuilder.addBuildStep(new BuildStep() { | ||
@Override | ||
public void execute(BuildContext context) { | ||
context.produce(new AllowNotRestParametersBuildItem()); | ||
} | ||
}).produces(AllowNotRestParametersBuildItem.class).build(); | ||
} | ||
}) | ||
.withApplicationRoot((jar) -> jar | ||
.addClass(MixedParameterResource.class)); | ||
|
||
@Test | ||
@DisplayName("Test Resource Method with one param not related to RESTEasy") | ||
public void shouldOkEvenNotResteasyParameterPresence() { | ||
given() | ||
.body("value") | ||
.post("/" + MixedParameterResource.class.getSimpleName() + "/mixed?foo=bar") | ||
.then().statusCode(200).body(is("bar.value")); | ||
} | ||
|
||
@Test | ||
@DisplayName("Test Resource Method with only one param not related to RESTEasy") | ||
public void shouldOkEvenNotResteasySingleParameterPresence() { | ||
given() | ||
.body("value") | ||
.get("/" + MixedParameterResource.class.getSimpleName() + "/single") | ||
.then().statusCode(200); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...quarkus/resteasy/reactive/server/test/resource/basic/resource/MixedParameterResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.quarkus.resteasy.reactive.server.test.resource.basic.resource; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
|
||
@Path("/MixedParameterResource") | ||
public class MixedParameterResource { | ||
|
||
@POST | ||
@Path("/mixed") | ||
public String mixedParam(@OtherAnnotation MyOtherObject otherObject, @QueryParam("foo") String query, String body) { | ||
return query.concat(".").concat(body); | ||
} | ||
|
||
@GET | ||
@Path("/single") | ||
public String singleParam(@OtherAnnotation MyOtherObject otherObject) { | ||
return "ok"; | ||
} | ||
|
||
public static class MyOtherObject { | ||
String param; | ||
|
||
public String getParam() { | ||
return param; | ||
} | ||
|
||
public void setParam(String param) { | ||
this.param = param; | ||
} | ||
} | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ ElementType.FIELD, ElementType.PARAMETER }) | ||
public @interface OtherAnnotation { | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...rc/main/java/io/quarkus/resteasy/reactive/server/spi/AllowNotRestParametersBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.quarkus.resteasy.reactive.server.spi; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* A build item which extensions can generate when they want to allow RESTEasy Reactive methods | ||
* with parameters that are annotated with not REST annotations. This allows RESTEasy Reactive to let mixed parameters coexist | ||
* within resource methods signature | ||
*/ | ||
public final class AllowNotRestParametersBuildItem extends SimpleBuildItem { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little Javadoc on what this done would be great
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done