Skip to content

Commit

Permalink
Correctly handle @path annotations that has params with regexes (#600)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyegupov authored and kdavisk6 committed Sep 14, 2018
1 parent b40498f commit 3c7bca0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ protected void processAnnotationOnClass(MethodMetadata data, Class<?> clz) {
// added
pathValue = pathValue.substring(0, pathValue.length() - 1);
}
// jax-rs allows whitespace around the param name, as well as an optional regex. The contract should
// strip these out appropriately.
pathValue = pathValue.replaceAll("\\{\\s*(.+?)\\s*(:.+?)?\\}", "\\{$1\\}");
data.template().insert(0, pathValue);
}
Consumes consumes = clz.getAnnotation(Consumes.class);
Expand Down
14 changes: 13 additions & 1 deletion jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,18 @@ public void pathParamWithSpaces() throws Exception {
}

@Test
public void regexPathOnMethod() throws Exception {
public void regexPathOnMethodOrType() throws Exception {
assertThat(parseAndValidateMetadata(
PathOnType.class, "pathParamWithRegex", String.class).template())
.hasUrl("/base/regex/{param}");

assertThat(parseAndValidateMetadata(
PathOnType.class, "pathParamWithMultipleRegex", String.class, String.class).template())
.hasUrl("/base/regex/{param1}/{param2}");

assertThat(parseAndValidateMetadata(
ComplexPathOnType.class, "pathParamWithMultipleRegex", String.class, String.class).template())
.hasUrl("/{baseparam}/regex/{param1}/{param2}");
}

@Test
Expand Down Expand Up @@ -527,6 +531,14 @@ Response pathParamWithMultipleRegex(@PathParam("param1") String param1,
@PathParam("param2") String param2);
}

@Path("/{baseparam: [0-9]+}")
interface ComplexPathOnType {

@GET
@Path("regex/{param1:[0-9]*}/{ param2 : .+}")
Response pathParamWithMultipleRegex(@PathParam("param1") String param1, @PathParam("param2") String param2);
}

interface WithURIParam {

@GET
Expand Down

0 comments on commit 3c7bca0

Please sign in to comment.