Skip to content

Commit

Permalink
Address PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
puppy4c committed Apr 20, 2024
1 parent 724d632 commit c26d64e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/spring-cloud-openfeign.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface StoreClient {
@GetMapping("/stores")
Page<Store> getStores(Pageable pageable);
@PostMapping(value = "/stores/{storeId}", consumes = "application/json")
@PostMapping(value = "/stores/{storeId}", consumes = "application/json", params = "mode=upsert")
Store update(@PathVariable("storeId") Long storeId, Store store);
@DeleteMapping("/stores/{storeId:\\d+}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ private void parseParams(MethodMetadata data, Method method, RequestMapping meth
if (!nameValueResolver.isNegated()) {
data.template().query(resolve(nameValueResolver.getName()), resolve(nameValueResolver.getValue()));
}
else {
throw new IllegalArgumentException("Negated params are not supported: " + param);
}
}
}

Expand Down Expand Up @@ -493,15 +496,14 @@ private static class NameValueResolver {
NameValueResolver(String expression) {
int separator = expression.indexOf('=');
if (separator == -1) {
this.isNegated = expression.startsWith("!");
this.name = (this.isNegated ? expression.substring(1) : expression);
this.value = null;
isNegated = expression.startsWith("!");
name = (isNegated ? expression.substring(1) : expression);
value = null;
}
else {
this.isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
this.name = (this.isNegated ? expression.substring(0, separator - 1)
: expression.substring(0, separator));
this.value = expression.substring(separator + 1);
isNegated = (separator > 0) && (expression.charAt(separator - 1) == '!');
name = (isNegated ? expression.substring(0, separator - 1) : expression.substring(0, separator));
value = expression.substring(separator + 1);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,18 @@ void testProcessAnnotations_ParseParams_MultipleParamsWithoutValue() throws Exce

@Test
void testProcessAnnotations_ParseParams_NotEqualParams() throws Exception {
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams");
assertThatIllegalArgumentException().isThrownBy(() -> {
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams");
contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
});
}

@Test
void testProcessAnnotations_ParseParams_ParamsAndRequestParam() throws Exception {
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("paramsAndRequestParam", String.class);
MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);

assertThat(data.template().url()).isEqualTo("/test");
assertThat(data.template().url()).isEqualTo("/test?p1=1&p2={p2}");
assertThat(data.template().method()).isEqualTo("GET");
}

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

@GetMapping(value = "test", params = { "p1=1" })
ResponseEntity<TestObject> paramsAndRequestParam(@RequestParam("p2") String p2);

}

public interface TestTemplate_HeaderMap {
Expand Down

0 comments on commit c26d64e

Please sign in to comment.