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

Support record parameter containers #42642

Merged
merged 1 commit into from
Aug 26, 2024
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
24 changes: 24 additions & 0 deletions docs/src/main/asciidoc/rest.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,30 @@
----
<1> `BeanParam` is required to comply with the Jakarta REST specification so that libraries like OpenAPI can introspect the parameters.

Record classes are also supported, so you could rewrite the previous example as a record:

Check warning on line 397 in docs/src/main/asciidoc/rest.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/rest.adoc", "range": {"start": {"line": 397, "column": 78}}}, "severity": "INFO"}

[source,java]
----
public record Parameters(
@RestPath
String type,

@RestMatrix
String variant,

@RestQuery
String age,

@RestCookie
String level,

@RestHeader("X-Cheese-Secret-Handshake")
String secretHandshake,

@RestForm
String smell){}
----

[[uri-parameters]]
=== [[declaring-uri-parameters]] Declaring URI parameters

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.resteasy.reactive.common.deployment;

import java.util.Set;

import org.jboss.jandex.DotName;

import io.quarkus.builder.item.SimpleBuildItem;

public final class AggregatedParameterContainersBuildItem extends SimpleBuildItem {

/**
* This contains all the parameter containers (bean param classes and records) as well as resources/endpoints
*/
private final Set<DotName> classNames;
/**
* This contains all the non-record parameter containers (bean param classes only) as well as resources/endpoints
*/
private final Set<DotName> nonRecordClassNames;

public AggregatedParameterContainersBuildItem(Set<DotName> classNames, Set<DotName> nonRecordClassNames) {
this.classNames = classNames;
this.nonRecordClassNames = nonRecordClassNames;
}

/**
* All class names
*/
public Set<DotName> getClassNames() {
return classNames;
}

/**
* All class names minus the records
*/
public Set<DotName> getNonRecordClassNames() {
return nonRecordClassNames;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,41 @@ private CustomResourceProducersGenerator() {
* &#64;Singleton
* public class ResourcesWithParamProducer {
*
* &#64;Inject
* CurrentVertxRequest currentVertxRequest;
* private String getHeaderParam(String name) {
* return (String)new HeaderParamExtractor(name, true).extractParameter(getContext());
* }
*
* private String getQueryParam(String name) {
* return (String)new QueryParamExtractor(name, true, false, null).extractParameter(getContext());
* }
*
* private String getPathParam(int index) {
* return (String)new PathParamExtractor(index, false, true).extractParameter(getContext());
* }
*
* private String getMatrixParam(String name) {
* return (String)new MatrixParamExtractor(name, true, false).extractParameter(getContext());
* }
*
* private String getCookieParam(String name) {
* return (String)new CookieParamExtractor(name, null).extractParameter(getContext());
* }
*
* &#64;Produces
* &#64;RequestScoped
* public QueryParamResource producer_QueryParamResource_somehash(UriInfo uriInfo) {
* return new QueryParamResource(getContext().getContext().queryParams().get("p1"), uriInfo);
* return new QueryParamResource(getQueryParam("p1"), uriInfo);
* }
*
* private QuarkusRestRequestContext getContext() {
* return (QuarkusRestRequestContext) currentVertxRequest.getOtherHttpContextObject();
* private ResteasyReactiveRequestContext getContext() {
* return CurrentRequestManager.get();
* }
* }
*
* </pre></code>
*/
public static void generate(Map<DotName, MethodInfo> resourcesThatNeedCustomProducer,
Set<String> beanParamsThatNeedCustomProducer,
Set<DotName> parameterContainersThatNeedCustomProducer,
BuildProducer<GeneratedBeanBuildItem> generatedBeanBuildItemBuildProducer,
BuildProducer<AdditionalBeanBuildItem> additionalBeanBuildItemBuildProducer) {
GeneratedBeanGizmoAdaptor classOutput = new GeneratedBeanGizmoAdaptor(generatedBeanBuildItemBuildProducer);
Expand Down Expand Up @@ -307,7 +324,8 @@ public static void generate(Map<DotName, MethodInfo> resourcesThatNeedCustomProd
}
// FIXME: support constructors for bean params too
additionalBeanBuildItemBuildProducer
.produce(AdditionalBeanBuildItem.builder().addBeanClasses(beanParamsThatNeedCustomProducer)
.produce(AdditionalBeanBuildItem.builder()
.addBeanClasses(parameterContainersThatNeedCustomProducer.stream().map(DotName::toString).toList())
// FIXME: we should add this, but for that we also need to make the resource class request-scoped
// .setDefaultScope(DOTNAME_REQUEST_SCOPED)
// .setUnremovable()
Expand Down
Loading
Loading