Skip to content

Commit b85d5c1

Browse files
author
Jacob Meacham
committed
Fix an issue with trailing slashes in @path annotations on classes
1 parent 0bc994e commit b85d5c1

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

jaxrs/src/main/java/feign/jaxrs/JAXRSContract.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ public MethodMetadata parseAndValidatateMetadata(Method method) {
5454
if (!pathValue.startsWith("/")) {
5555
pathValue = "/" + pathValue;
5656
}
57+
if (pathValue.endsWith("/")) {
58+
// Strip off any trailing slashes, since the template has already had slashes appropriately added
59+
pathValue = pathValue.substring(0, pathValue.length()-1);
60+
}
5761
md.template().insert(0, pathValue);
5862
}
5963
return md;

jaxrs/src/test/java/feign/jaxrs/JAXRSContractTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,22 @@ public void pathsWithSomeOtherSlashesParseCorrectly() throws Exception {
374374

375375
}
376376

377+
@Test
378+
public void classWithRootPathParsesCorrectly() throws Exception {
379+
assertThat(
380+
contract.parseAndValidatateMetadata(ClassRootPath.class.getDeclaredMethod("get"))
381+
.template())
382+
.hasUrl("/specific");
383+
}
384+
385+
@Test
386+
public void classPathWithTrailingSlashParsesCorrectly() throws Exception {
387+
assertThat(
388+
contract.parseAndValidatateMetadata(ClassPathWithTrailingSlash.class.getDeclaredMethod("get"))
389+
.template())
390+
.hasUrl("/base/specific");
391+
}
392+
377393
interface Methods {
378394

379395
@POST
@@ -549,4 +565,18 @@ interface PathsWithSomeOtherSlashes {
549565
@Path("/specific")
550566
Response get();
551567
}
568+
569+
@Path("/")
570+
interface ClassRootPath {
571+
@GET
572+
@Path("/specific")
573+
Response get();
574+
}
575+
576+
@Path("/base/")
577+
interface ClassPathWithTrailingSlash {
578+
@GET
579+
@Path("/specific")
580+
Response get();
581+
}
552582
}

0 commit comments

Comments
 (0)