Skip to content

Commit 3e5d29b

Browse files
Jacob MeachamAdrian Cole
authored andcommitted
Fix an issue with trailing slashes in @path annotations on classes
1 parent 39797f0 commit 3e5d29b

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
@@ -381,6 +381,22 @@ public void pathsWithSomeOtherSlashesParseCorrectly() throws Exception {
381381

382382
}
383383

384+
@Test
385+
public void classWithRootPathParsesCorrectly() throws Exception {
386+
assertThat(
387+
contract.parseAndValidatateMetadata(ClassRootPath.class.getDeclaredMethod("get"))
388+
.template())
389+
.hasUrl("/specific");
390+
}
391+
392+
@Test
393+
public void classPathWithTrailingSlashParsesCorrectly() throws Exception {
394+
assertThat(
395+
contract.parseAndValidatateMetadata(ClassPathWithTrailingSlash.class.getDeclaredMethod("get"))
396+
.template())
397+
.hasUrl("/base/specific");
398+
}
399+
384400
interface Methods {
385401

386402
@POST
@@ -560,4 +576,18 @@ interface PathsWithSomeOtherSlashes {
560576
@Path("/specific")
561577
Response get();
562578
}
579+
580+
@Path("/")
581+
interface ClassRootPath {
582+
@GET
583+
@Path("/specific")
584+
Response get();
585+
}
586+
587+
@Path("/base/")
588+
interface ClassPathWithTrailingSlash {
589+
@GET
590+
@Path("/specific")
591+
Response get();
592+
}
563593
}

0 commit comments

Comments
 (0)