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
This commit is contained in:
@@ -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.RequestHeaderParameterProcessor;
|
||||
import org.springframework.cloud.netflix.feign.annotation.RequestParamParameterProcessor;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@@ -166,7 +167,7 @@ public class SpringMvcContract extends Contract.BaseContract {
|
||||
.get(parameterAnnotation.annotationType());
|
||||
if (processor != null) {
|
||||
isHttpAnnotation |= processor.processArgument(context,
|
||||
parameterAnnotation);
|
||||
AnnotationUtils.synthesizeAnnotation(parameterAnnotation, null));
|
||||
}
|
||||
}
|
||||
return isHttpAnnotation;
|
||||
|
||||
@@ -26,7 +26,7 @@ import lombok.ToString;
|
||||
/**
|
||||
* @author chadjaros
|
||||
*/
|
||||
public class SpringMvcContractTest {
|
||||
public class SpringMvcContractTests {
|
||||
|
||||
private SpringMvcContract contract;
|
||||
|
||||
@@ -122,6 +122,27 @@ public class SpringMvcContractTest {
|
||||
data.template().queries().get("amount").iterator().next());
|
||||
}
|
||||
|
||||
@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 {
|
||||
Method method = TestTemplate_Advanced.class.getDeclaredMethod("getTest");
|
||||
@@ -166,6 +187,10 @@ public class SpringMvcContractTest {
|
||||
ResponseEntity<TestObject> getTest(@RequestHeader("Authorization") String auth,
|
||||
@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)
|
||||
TestObject getTest();
|
||||
}
|
||||
@@ -209,4 +234,4 @@ public class SpringMvcContractTest {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user