From 08604924461afd6afb26116ac725e3997eb40252 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BB=98?= <925456043@qq.com> Date: Mon, 3 Aug 2026 14:51:34 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BA=E5=AE=9A=E5=85=AC=E5=85=B1?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=B5=81=E6=8E=A5=E5=8F=A3=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 统一声明 application/json 响应并补充契约测试 --- .../controller/PublicWorkflowController.java | 3 ++- .../PublicWorkflowControllerContractTest.java | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 easyflow-api/easyflow-api-public/src/test/java/tech/easyflow/publicapi/controller/PublicWorkflowControllerContractTest.java diff --git a/easyflow-api/easyflow-api-public/src/main/java/tech/easyflow/publicapi/controller/PublicWorkflowController.java b/easyflow-api/easyflow-api-public/src/main/java/tech/easyflow/publicapi/controller/PublicWorkflowController.java index 7c0e1ab2..6044e0f7 100644 --- a/easyflow-api/easyflow-api-public/src/main/java/tech/easyflow/publicapi/controller/PublicWorkflowController.java +++ b/easyflow-api/easyflow-api-public/src/main/java/tech/easyflow/publicapi/controller/PublicWorkflowController.java @@ -6,6 +6,7 @@ import com.easyagents.flow.core.chain.runtime.ChainExecutor; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.constraints.NotBlank; +import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import tech.easyflow.approval.annotation.RequirePublishedAccess; import tech.easyflow.ai.easyagentsflow.entity.ChainInfo; @@ -38,7 +39,7 @@ import java.util.Map; /** * 工作流 */ -@RequestMapping("/public-api/workflow") +@RequestMapping(value = "/public-api/workflow", produces = MediaType.APPLICATION_JSON_VALUE) @RestController public class PublicWorkflowController { diff --git a/easyflow-api/easyflow-api-public/src/test/java/tech/easyflow/publicapi/controller/PublicWorkflowControllerContractTest.java b/easyflow-api/easyflow-api-public/src/test/java/tech/easyflow/publicapi/controller/PublicWorkflowControllerContractTest.java new file mode 100644 index 00000000..90baf433 --- /dev/null +++ b/easyflow-api/easyflow-api-public/src/test/java/tech/easyflow/publicapi/controller/PublicWorkflowControllerContractTest.java @@ -0,0 +1,26 @@ +package tech.easyflow.publicapi.controller; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * {@link PublicWorkflowController} HTTP 响应契约测试。 + */ +public class PublicWorkflowControllerContractTest { + + /** + * 验证工作流公共 API 明确返回 JSON,避免通配 Accept 请求被 CBOR 转换器接管。 + */ + @Test + public void shouldDeclareJsonResponseMediaType() { + RequestMapping requestMapping = PublicWorkflowController.class.getAnnotation(RequestMapping.class); + + Assert.assertNotNull(requestMapping); + Assert.assertArrayEquals( + new String[]{MediaType.APPLICATION_JSON_VALUE}, + requestMapping.produces() + ); + } +}