Skip to content

Commit 15b48c1

Browse files
author
adriancole
committed
fix issue OpenFeign#31: support @path on type
1 parent f21b1a0 commit 15b48c1

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Version 3.2
88
* Add wikipedia search example
9+
* Allow `@Path` on types in feign-jaxrs
910

1011
### Version 3.1
1112
* Log when an http request is retried or a response fails due to an IOException.

feign-jaxrs/src/main/java/feign/jaxrs/JAXRSModule.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ public final class JAXRSModule {
4545

4646
public static final class JAXRSContract extends Contract.BaseContract {
4747

48+
@Override
49+
public MethodMetadata parseAndValidatateMetadata(Method method) {
50+
MethodMetadata md = super.parseAndValidatateMetadata(method);
51+
Path path = method.getDeclaringClass().getAnnotation(Path.class);
52+
if (path != null) {
53+
md.template().insert(0, path.value());
54+
}
55+
return md;
56+
}
57+
4858
@Override
4959
protected void processAnnotationOnMethod(MethodMetadata data, Annotation methodAnnotation, Method method) {
5060
Class<? extends Annotation> annotationType = methodAnnotation.annotationType();

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ public void tooManyBodies() throws Exception {
193193
contract.parseAndValidatateMetadata(BodyParams.class.getDeclaredMethod("tooMany", List.class, List.class));
194194
}
195195

196+
@Path("/base")
197+
interface PathOnType {
198+
@GET Response base();
199+
200+
@GET @Path("/specific") Response get();
201+
}
202+
203+
@Test public void pathOnType() throws Exception {
204+
MethodMetadata md = contract.parseAndValidatateMetadata(PathOnType.class.getDeclaredMethod("base"));
205+
assertEquals(md.template().url(), "/base");
206+
md = contract.parseAndValidatateMetadata(PathOnType.class.getDeclaredMethod("get"));
207+
assertEquals(md.template().url(), "/base/specific");
208+
}
209+
196210
interface WithURIParam {
197211
@GET @Path("/{1}/{2}") Response uriParam(@PathParam("1") String one, URI endpoint, @PathParam("2") String two);
198212
}

0 commit comments

Comments
 (0)