This is an automated email from the ASF dual-hosted git repository.
Aias00 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 5f32a59e9a fix(client): read the produces/consumes keys the spring-mvc
extractor writes (#7332)
5f32a59e9a is described below
commit 5f32a59e9acf58573fa1a13fa7ee8f6341f2acbd
Author: Sean-Walker0 <[email protected]>
AuthorDate: Mon Sep 28 12:16:46 2026 +0800
fix(client): read the produces/consumes keys the spring-mvc extractor
writes (#7332)
RequestMappingProcessor stores the media types under the plural keys
"produces"/"consumes" (it is the only writer in the repository), but
ApiDocRegistrarImpl#getProduce/getConsume looked up the singular
"produce"/"consume", which nothing ever writes. Every API document
registered through the spring-mvc extractor therefore fell back to
*/* regardless of @RequestMapping(produces/consumes), and the singular
keys could never be honored. Read the plural keys so the configured
media types reach the registered API docs.
The new test fails on current master (expected application/json but
was */*) and passes with this change.
Co-authored-by: Sean-Walker0
<[email protected]>
Co-authored-by: aias00 <[email protected]>
---
.../register/registrar/ApiDocRegistrarImpl.java | 4 ++--
.../registrar/ApiDocRegistrarImplTest.java | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java
index b4bd04ca9b..4ca08335b6 100644
---
a/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java
+++
b/shenyu-client/shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImpl.java
@@ -172,7 +172,7 @@ public class ApiDocRegistrarImpl extends
BaseApiRegistrarImpl {
}
private String getProduce(final ApiBean.ApiDefinition api) {
- final String produce = api.getPropertiesValue("produce");
+ final String produce = api.getPropertiesValue("produces");
if (StringUtils.isBlank(produce)) {
return ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE;
}
@@ -180,7 +180,7 @@ public class ApiDocRegistrarImpl extends
BaseApiRegistrarImpl {
}
private static String getConsume(final ApiBean.ApiDefinition api) {
- final String consume = api.getPropertiesValue("consume");
+ final String consume = api.getPropertiesValue("consumes");
if (StringUtils.isBlank(consume)) {
return ShenyuClientConstants.MEDIA_TYPE_ALL_VALUE;
}
diff --git
a/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImplTest.java
b/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImplTest.java
index 31a024d5ae..2803c17127 100644
---
a/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImplTest.java
+++
b/shenyu-client/shenyu-client-core/src/test/java/org/apache/shenyu/client/core/register/registrar/ApiDocRegistrarImplTest.java
@@ -29,6 +29,7 @@ import java.util.Map;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class ApiDocRegistrarImplTest {
@@ -157,6 +158,27 @@ public class ApiDocRegistrarImplTest {
// --- Inner types (must be after all methods per checkstyle
InnerTypeLast) ---
+ @Test
+ void testProduceAndConsumeReadTheKeysTheSpringMvcExtractorWrites() throws
Exception {
+ ApiBean apiBean = new ApiBean(RpcTypeEnum.HTTP.getName(),
+ TestHttpService.class.getName(),
+ TestHttpService.class.getDeclaredConstructor().newInstance(),
+ "httpTestService");
+ apiBean.addApiDefinition(TestHttpService.class.getMethod("findById",
String.class), "/findById");
+ ApiBean.ApiDefinition definition = apiBean.getApiDefinitions().get(0);
+ // RequestMappingProcessor is the only writer of these properties and
uses the plural keys
+ definition.addProperties("produces", "application/json");
+ definition.addProperties("consumes", "application/xml");
+
+ Method getProduce =
ApiDocRegistrarImpl.class.getDeclaredMethod("getProduce",
ApiBean.ApiDefinition.class);
+ getProduce.setAccessible(true);
+ Method getConsume =
ApiDocRegistrarImpl.class.getDeclaredMethod("getConsume",
ApiBean.ApiDefinition.class);
+ getConsume.setAccessible(true);
+
+ assertEquals("application/json", getProduce.invoke(httpRegistrar,
definition));
+ assertEquals("application/xml", getConsume.invoke(httpRegistrar,
definition));
+ }
+
public static class TestDubboService {
public Object findById(final String id) {
return null;