Skip to content

Commit

Permalink
Allow List<PathSegment> injection
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Oct 26, 2021
1 parent 834ed9d commit 47757cc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.function.Predicate;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.ClassInfo;
Expand All @@ -26,6 +27,7 @@
import org.jboss.resteasy.reactive.server.core.parameters.converters.NoopParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.ParameterConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.ParameterConverterSupplier;
import org.jboss.resteasy.reactive.server.core.parameters.converters.PathSegmentParamConverter;
import org.jboss.resteasy.reactive.server.core.parameters.converters.RuntimeResolvedConverter;
import org.jboss.resteasy.reactive.server.processor.ServerEndpointIndexer;
import org.jboss.resteasy.reactive.server.processor.ServerIndexedParameter;
Expand Down Expand Up @@ -133,6 +135,8 @@ protected ParameterConverterSupplier extractConverter(String elementType, IndexV
if (delegate == null)
throw new RuntimeException("Failed to find converter for " + elementType);
return delegate;
} else if (elementType.equals(PathSegment.class.getName())) {
return new PathSegmentParamConverter.Supplier();
}

MethodDescriptor fromString = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.quarkus.resteasy.reactive.server.test.path;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.PathSegment;

/**
* Per spec:
Expand All @@ -25,4 +29,10 @@ public String hello() {
public String nested() {
return "world hello";
}

@GET
@Path("other/{keyword:.*}")
public String searchByKeywords(@PathParam("keyword") List<PathSegment> keywords) {
return keywords.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ public void testRestPath() {
RestAssured.when().get("/app/foo/hello").then().statusCode(200).body(Matchers.is("hello"));
RestAssured.when().get("/app/foo/hello/nested").then().statusCode(200).body(Matchers.is("world hello"));
}

@Test
public void testListOfPathParams() {
RestAssured.basePath = "/";
RestAssured.when().get("/app/foo/hello/other/bar/baz/boo/bob").then().statusCode(200)
.body(Matchers.is("[bar, baz, boo, bob]"));
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
package org.jboss.resteasy.reactive.server.core.parameters;

import java.util.List;
import org.jboss.resteasy.reactive.common.util.Encode;
import org.jboss.resteasy.reactive.server.core.ResteasyReactiveRequestContext;

public class PathParamExtractor implements ParameterExtractor {

private final int index;
private final boolean encoded;
private final boolean single;

public PathParamExtractor(int index, boolean encoded) {
public PathParamExtractor(int index, boolean encoded, boolean single) {
this.index = index;
this.encoded = encoded;
this.single = single;
}

@Override
public Object extractParameter(ResteasyReactiveRequestContext context) {
String pathParam = context.getPathParam(index);
if (encoded) {
return Encode.encodeQueryParam(pathParam);
pathParam = Encode.encodeQueryParam(pathParam);
}
if (single) {
return pathParam;
} else {
return List.of(pathParam.split("/"));
}
return pathParam;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public ParameterExtractor parameterExtractor(Map<String, Integer> pathParameterI
extractor = new NullParamExtractor();
}
} else {
extractor = new PathParamExtractor(index, encoded);
extractor = new PathParamExtractor(index, encoded, single);
}
return extractor;
case CONTEXT:
Expand Down

0 comments on commit 47757cc

Please sign in to comment.