Skip to content

Commit

Permalink
Support record parameter containers
Browse files Browse the repository at this point in the history
Also unify the parameter container detection code paths
Make sure we do not turn record parameter containers into beans
For records, we store every contructor parameter in a local variable
until we have enough to call the constructor via a generated static
method.

Fixes quarkusio#19686
  • Loading branch information
FroMage committed Aug 20, 2024
1 parent e4030a9 commit 8bf1d9a
Show file tree
Hide file tree
Showing 18 changed files with 783 additions and 260 deletions.
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 @@ public class Endpoint {
----
<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:

[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,32 @@
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 {

private final Set<DotName> classNames;
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

0 comments on commit 8bf1d9a

Please sign in to comment.