Skip to content

Commit c26d64e

Browse files
author
puppy4c
committed
Address PR Comments
1 parent 724d632 commit c26d64e

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

docs/modules/ROOT/pages/spring-cloud-openfeign.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public interface StoreClient {
4545
@GetMapping("/stores")
4646
Page<Store> getStores(Pageable pageable);
4747
48-
@PostMapping(value = "/stores/{storeId}", consumes = "application/json")
48+
@PostMapping(value = "/stores/{storeId}", consumes = "application/json", params = "mode=upsert")
4949
Store update(@PathVariable("storeId") Long storeId, Store store);
5050
5151
@DeleteMapping("/stores/{storeId:\\d+}")

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ private void parseParams(MethodMetadata data, Method method, RequestMapping meth
368368
if (!nameValueResolver.isNegated()) {
369369
data.template().query(resolve(nameValueResolver.getName()), resolve(nameValueResolver.getValue()));
370370
}
371+
else {
372+
throw new IllegalArgumentException("Negated params are not supported: " + param);
373+
}
371374
}
372375
}
373376

@@ -493,15 +496,14 @@ private static class NameValueResolver {
493496
NameValueResolver(String expression) {
494497
int separator = expression.indexOf('=');
495498
if (separator == -1) {
496-
this.isNegated = expression.startsWith("!");
497-
this.name = (this.isNegated ? expression.substring(1) : expression);
498-
this.value = null;
499+
isNegated = expression.startsWith("!");
500+
name = (isNegated ? expression.substring(1) : expression);
501+
value = null;
499502
}
500503
else {
501-
this.isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
502-
this.name = (this.isNegated ? expression.substring(0, separator - 1)
503-
: expression.substring(0, separator));
504-
this.value = expression.substring(separator + 1);
504+
isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
505+
name = (isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator));
506+
value = expression.substring(separator + 1);
505507
}
506508
}
507509

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,10 +510,18 @@ void testProcessAnnotations_ParseParams_MultipleParamsWithoutValue() throws Exce
510510

511511
@Test
512512
void testProcessAnnotations_ParseParams_NotEqualParams() throws Exception {
513-
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams");
513+
assertThatIllegalArgumentException().isThrownBy(() -> {
514+
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams");
515+
contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
516+
});
517+
}
518+
519+
@Test
520+
void testProcessAnnotations_ParseParams_ParamsAndRequestParam() throws Exception {
521+
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("paramsAndRequestParam", String.class);
514522
MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
515523

516-
assertThat(data.template().url()).isEqualTo("/test");
524+
assertThat(data.template().url()).isEqualTo("/test?p1=1&p2={p2}");
517525
assertThat(data.template().method()).isEqualTo("GET");
518526
}
519527

@@ -825,6 +833,9 @@ public interface TestTemplate_ParseParams {
825833
@GetMapping(value = "test", params = { "p1!=1" })
826834
ResponseEntity<TestObject> notEqualParams();
827835

836+
@GetMapping(value = "test", params = { "p1=1" })
837+
ResponseEntity<TestObject> paramsAndRequestParam(@RequestParam("p2") String p2);
838+
828839
}
829840

830841
public interface TestTemplate_HeaderMap {

0 commit comments

Comments
 (0)