Merge remote-tracking branch 'origin/4.1.x' into 4.2.x

This commit is contained in:
Olga Maciaszek-Sharma
2025-03-13 13:43:57 +01:00
2 changed files with 24 additions and 32 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 the original author or authors.
* Copyright 2013-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -279,16 +279,16 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
}
// produces
parseProduces(data, method, methodMapping);
parseProduces(data, methodMapping);
// consumes
parseConsumes(data, method, methodMapping);
parseConsumes(data, methodMapping);
// headers
parseHeaders(data, method, methodMapping);
parseHeaders(data, methodMapping);
// params
parseParams(data, method, methodMapping);
parseParams(data, methodMapping);
data.indexToExpander(new LinkedHashMap<>());
}
@@ -371,7 +371,7 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
return false;
}
private void parseProduces(MethodMetadata md, Method method, RequestMapping annotation) {
private void parseProduces(MethodMetadata md, RequestMapping annotation) {
String[] serverProduces = annotation.produces();
String clientAccepts = serverProduces.length == 0 ? null : emptyToNull(serverProduces[0]);
if (clientAccepts != null) {
@@ -379,7 +379,7 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
}
}
private void parseConsumes(MethodMetadata md, Method method, RequestMapping annotation) {
private void parseConsumes(MethodMetadata md, RequestMapping annotation) {
String[] serverConsumes = annotation.consumes();
String clientProduces = serverConsumes.length == 0 ? null : emptyToNull(serverConsumes[0]);
if (clientProduces != null) {
@@ -387,9 +387,9 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
}
}
private void parseHeaders(MethodMetadata md, Method method, RequestMapping annotation) {
private void parseHeaders(MethodMetadata md, RequestMapping annotation) {
// TODO: only supports one header value per key
if (annotation.headers() != null && annotation.headers().length > 0) {
if (annotation.headers() != null) {
for (String header : annotation.headers()) {
int index = header.indexOf('=');
if (!header.contains("!=") && index >= 0) {
@@ -400,9 +400,9 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
}
}
private void parseParams(MethodMetadata data, Method method, RequestMapping methodMapping) {
private void parseParams(MethodMetadata data, RequestMapping methodMapping) {
String[] params = methodMapping.params();
if (params == null || params.length == 0) {
if (params == null) {
return;
}
for (String param : params) {
@@ -411,7 +411,10 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
data.template().query(resolve(nameValueResolver.getName()), resolve(nameValueResolver.getValue()));
}
else {
throw new IllegalArgumentException("Negated params are not supported: " + param);
if (LOG.isDebugEnabled()) {
LOG.debug("Negated params are not supported by Feign and ignored during parameter processing: "
+ param);
}
}
}
}
@@ -477,13 +480,7 @@ public class SpringMvcContract extends Contract.BaseContract implements Resource
return false;
}
private static class ConvertingExpanderFactory {
private final ConversionService conversionService;
ConvertingExpanderFactory(ConversionService conversionService) {
this.conversionService = conversionService;
}
private record ConvertingExpanderFactory(ConversionService conversionService) {
Param.Expander getExpander(TypeDescriptor typeDescriptor) {
return value -> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2024 the original author or authors.
* Copyright 2013-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ import static com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility.NONE;
import static feign.CollectionFormat.CSV;
import static feign.CollectionFormat.SSV;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@@ -567,11 +568,11 @@ class SpringMvcContractTests {
}
@Test
void testProcessAnnotations_ParseParams_NotEqualParams() throws Exception {
assertThatIllegalArgumentException().isThrownBy(() -> {
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("notEqualParams");
void testProcessAnnotations_ParseParams_NegatedParams() {
assertThatCode(() -> {
Method method = TestTemplate_ParseParams.class.getDeclaredMethod("negatedParams");
contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
});
}).doesNotThrowAnyException();
}
@Test
@@ -895,7 +896,7 @@ class SpringMvcContractTests {
ResponseEntity<TestObject> mixParams();
@GetMapping(value = "test", params = { "p1!=1" })
ResponseEntity<TestObject> notEqualParams();
ResponseEntity<TestObject> negatedParams();
@GetMapping(value = "test", params = { "p1=1" })
ResponseEntity<TestObject> paramsAndRequestParam(@RequestParam("p2") String p2);
@@ -1066,13 +1067,7 @@ class SpringMvcContractTests {
@Override
public String toString() {
return new StringBuilder("TestObject{").append("something='")
.append(something)
.append("', ")
.append("number=")
.append(number)
.append("}")
.toString();
return "TestObject{" + "something='" + something + "', " + "number=" + number + "}";
}
}