Commit c3766720 by Matt Benson Committed by Dave Syer

Parameter name discovery for Feign clients

Supports Spring REST parameter annotations considered only #value() members without respecting @AliasFor meta-annotations. Address by passing a Spring-synthesized annotation to individual AnnotatedParameterProcessors. This approach has the benefit of impacting present as well as any future implementations alike. Fixes gh-828
parent c3efcbab
...@@ -30,6 +30,7 @@ import org.springframework.cloud.netflix.feign.AnnotatedParameterProcessor; ...@@ -30,6 +30,7 @@ import org.springframework.cloud.netflix.feign.AnnotatedParameterProcessor;
import org.springframework.cloud.netflix.feign.annotation.PathVariableParameterProcessor; import org.springframework.cloud.netflix.feign.annotation.PathVariableParameterProcessor;
import org.springframework.cloud.netflix.feign.annotation.RequestHeaderParameterProcessor; import org.springframework.cloud.netflix.feign.annotation.RequestHeaderParameterProcessor;
import org.springframework.cloud.netflix.feign.annotation.RequestParamParameterProcessor; import org.springframework.cloud.netflix.feign.annotation.RequestParamParameterProcessor;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -166,7 +167,7 @@ public class SpringMvcContract extends Contract.BaseContract { ...@@ -166,7 +167,7 @@ public class SpringMvcContract extends Contract.BaseContract {
.get(parameterAnnotation.annotationType()); .get(parameterAnnotation.annotationType());
if (processor != null) { if (processor != null) {
isHttpAnnotation |= processor.processArgument(context, isHttpAnnotation |= processor.processArgument(context,
parameterAnnotation); AnnotationUtils.synthesizeAnnotation(parameterAnnotation, null));
} }
} }
return isHttpAnnotation; return isHttpAnnotation;
......
...@@ -26,7 +26,7 @@ import lombok.ToString; ...@@ -26,7 +26,7 @@ import lombok.ToString;
/** /**
* @author chadjaros * @author chadjaros
*/ */
public class SpringMvcContractTest { public class SpringMvcContractTests {
private SpringMvcContract contract; private SpringMvcContract contract;
...@@ -123,6 +123,27 @@ public class SpringMvcContractTest { ...@@ -123,6 +123,27 @@ public class SpringMvcContractTest {
} }
@Test @Test
public void testProcessAnnotations_Aliased() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest2",
String.class, Integer.class);
MethodMetadata data = this.contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertEquals("/advanced/test2", data.template().url());
assertEquals("PUT", data.template().method());
assertEquals(MediaType.APPLICATION_JSON_VALUE,
data.template().headers().get("Accept").iterator().next());
assertEquals("Authorization", data.indexToName().get(0).iterator().next());
assertEquals("amount", data.indexToName().get(1).iterator().next());
assertEquals("{Authorization}",
data.template().headers().get("Authorization").iterator().next());
assertEquals("{amount}",
data.template().queries().get("amount").iterator().next());
}
@Test
public void testProcessAnnotations_Advanced2() throws Exception { public void testProcessAnnotations_Advanced2() throws Exception {
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest"); Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest");
MethodMetadata data = this.contract MethodMetadata data = this.contract
...@@ -166,6 +187,10 @@ public class SpringMvcContractTest { ...@@ -166,6 +187,10 @@ public class SpringMvcContractTest {
ResponseEntity<TestObject> getTest(@RequestHeader("Authorization") String auth, ResponseEntity<TestObject> getTest(@RequestHeader("Authorization") String auth,
@PathVariable("id") String id, @RequestParam("amount") Integer amount); @PathVariable("id") String id, @RequestParam("amount") Integer amount);
@RequestMapping(path = "/test2", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE)
ResponseEntity<TestObject> getTest2(@RequestHeader(name = "Authorization") String auth,
@RequestParam(name = "amount") Integer amount);
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) @RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
TestObject getTest(); TestObject getTest();
} }
...@@ -209,4 +234,4 @@ public class SpringMvcContractTest { ...@@ -209,4 +234,4 @@ public class SpringMvcContractTest {
return result; return result;
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment