Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 9.1
* Allows query parameters to match on a substring. Ex `q=body:{body}`

### Version 9.0
* Migrates to maven from gradle
* Changes maven groupId to `io.github.openfeign`
Expand Down
18 changes: 1 addition & 17 deletions core/src/main/java/feign/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[
isHttpAnnotation = true;
String varName = '{' + name + '}';
if (data.template().url().indexOf(varName) == -1 &&
!searchMapValuesContainsExact(data.template().queries(), varName) &&
!searchMapValuesContainsSubstring(data.template().queries(), varName) &&
!searchMapValuesContainsSubstring(data.template().headers(), varName)) {
data.formParams().add(name);
}
Expand All @@ -276,22 +276,6 @@ protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[
return isHttpAnnotation;
}

private static <K, V> boolean searchMapValuesContainsExact(Map<K, Collection<V>> map,
V search) {
Collection<Collection<V>> values = map.values();
if (values == null) {
return false;
}

for (Collection<V> entry : values) {
if (entry.contains(search)) {
return true;
}
}

return false;
}

private static <K, V> boolean searchMapValuesContainsSubstring(Map<K, Collection<String>> map,
String search) {
Collection<Collection<String>> values = map.values();
Expand Down
15 changes: 15 additions & 0 deletions core/src/test/java/feign/DefaultContractTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -770,4 +770,19 @@ public void defaultMethodsOnInterfaceIgnored() throws Exception {
MethodMetadata md = mds.get(0);
assertThat(md.configKey()).isEqualTo("DefaultMethodOnInterface#get(String)");
}

interface SubstringQuery {
@RequestLine("GET /_search?q=body:{body}")
String paramIsASubstringOfAQuery(@Param("body") String body);
}

@Test
public void paramIsASubstringOfAQuery() throws Exception {
List<MethodMetadata> mds = contract.parseAndValidatateMetadata(SubstringQuery.class);

assertThat(mds.get(0).template().queries()).containsExactly(
entry("q", asList("body:{body}"))
);
assertThat(mds.get(0).formParams()).isEmpty(); // Prevent issue 424
}
}