Browse Source

Fix handling adding multiple parametrs for key. Fixes gh-171. (#172)

pull/185/head
Olga Maciaszek-Sharma 6 years ago committed by GitHub
parent
commit
35ec2913d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignUtils.java
  2. 16
      spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java

3
spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/FeignUtils.java

@ -56,7 +56,8 @@ public final class FeignUtils { @@ -56,7 +56,8 @@ public final class FeignUtils {
static Collection<String> addTemplateParameter(Collection<String> possiblyNull,
String paramName) {
Collection<String> params = ofNullable(possiblyNull).orElse(new ArrayList<>());
Collection<String> params = ofNullable(possiblyNull).map(ArrayList::new)
.orElse(new ArrayList<>());
params.add(String.format("{%s}", paramName));
return params;
}

16
spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java

@ -523,6 +523,18 @@ public class SpringMvcContractTests { @@ -523,6 +523,18 @@ public class SpringMvcContractTests {
this.contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
}
@Test
public void testAddingTemplatedParameterWithTheSameKey()
throws NoSuchMethodException {
Method method = TestTemplate_Advanced.class.getDeclaredMethod(
"testAddingTemplatedParamForExistingKey", String.class);
MethodMetadata data = contract
.parseAndValidateMetadata(method.getDeclaringClass(), method);
assertThat(data.template().headers().get("Accept")).contains("application/json",
"{Accept}");
}
public interface TestTemplate_Simple {
@RequestMapping(value = "/test/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ -645,6 +657,10 @@ public class SpringMvcContractTests { @@ -645,6 +657,10 @@ public class SpringMvcContractTests {
@RequestMapping(method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
TestObject getTest();
@GetMapping(produces = "application/json")
String testAddingTemplatedParamForExistingKey(
@RequestHeader("Accept") String accept);
}
public interface TestTemplate_DateTimeFormatParameter {

Loading…
Cancel
Save