Skip to content

Commit

Permalink
Merge pull request quarkusio#42642 from FroMage/19686
Browse files Browse the repository at this point in the history
Support record parameter containers
  • Loading branch information
geoand authored Aug 26, 2024
2 parents 2105d46 + 9206f88 commit 4b8fcd3
Show file tree
Hide file tree
Showing 18 changed files with 798 additions and 266 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,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

0 comments on commit 4b8fcd3

Please sign in to comment.