feat(openapi): FormCenterSchemaClient 走标准 appCode 网关 fallback,application.yml 出厂 base-host 默认内部网关
build / build-push (push) Successful in 1m18s

This commit is contained in:
chenxing
2026-10-22 17:14:06 +08:00
parent 4b4d63e3ba
commit a10f2e054c
3 changed files with 44 additions and 2 deletions
@@ -25,7 +25,7 @@ import java.util.Map;
@Service
public class FormCenterSchemaClient {
/** 服务目录 key(yh.open.services.form-center / targets 覆盖 / 枚举兜底三级解析) */
/** 服务目录 key(targets / services 覆盖优先,否则标准 appCode 网关 fallback) */
static final String TARGET = "form-center";
static final String SCHEMA_PATH = "/oapi/form/schema";
/** 快照是发布期一次性动作,超时给足(对照 RouteJudgeClient 的 3s 运行期预算) */
+2 -1
View File
@@ -74,7 +74,8 @@ yh:
# 绝不能写进本文件:yh.open.services.{key} 是目录第 2 级,平台注入的 base-host 只喂第 3 级兜底、
# 压不过它 —— 写进 jar 会让部署实例去连容器内的 localhost:8060(2026-09-18 事故:
# Connection refused → 所有 /api/* 报 code=6 内部服务错误)。
base-host: http://localhost:8060
# 统一内部网关门地址;本地 UserBase 直连使用显式 services.userbase 覆盖。
base-host: ${YH_OPEN_BASE_HOST:http://open-gateway-service:10013}
base-path: ""
# 服务目录(子应用配置优化方案 §4.2):只在需要覆盖 PlatformService 枚举默认 ctx 时按 key 配置;
# prod 形态(网关域名 + 默认 ctx)下四域零配置。本地联调所需的 userbase 覆盖见上方环境变量。
@@ -0,0 +1,41 @@
package com.yunhai.flowcenter.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpServer;
import com.yunhai.platform.openapi.core.*;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class AppCodeFormCenterRoutingTest {
@Test
void realSdkNeedsOnlyGatewayForCatalogAndExactSchema() throws Exception {
List<String> paths = new ArrayList<>();
HttpServer gateway = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
gateway.createContext("/", exchange -> {
String path = exchange.getRequestURI().getPath(); paths.add(path);
String data = path.endsWith("/schema")
? "{\"formUuid\":\"test-form\",\"version\":3,\"groups\":[],\"audience\":[]}"
: "{\"items\":[],\"total\":0}";
byte[] bytes = ("{\"code\":0,\"data\":" + data + "}").getBytes(StandardCharsets.UTF_8);
exchange.sendResponseHeaders(200, bytes.length);
exchange.getResponseBody().write(bytes); exchange.close();
});
gateway.start();
try {
OpenApiProperties open = new OpenApiProperties();
open.setBaseHost("http://127.0.0.1:" + gateway.getAddress().getPort());
YschOpenCall call = new YschOpenCall(new YschCallProperties(), open, new ObjectMapper(), null);
assertFalse(call.hasTarget("form-center"));
assertEquals(0, new FormCenterCatalogClient(call).listForms(1L, null, null, 1, 20).getTotal());
assertEquals(3, new FormCenterSchemaClient(call, new ObjectMapper())
.fetchSchema(1L, "test-form", 3).get("formVersion"));
assertEquals(java.util.Arrays.asList("/form-center/oapi/form/forms", "/form-center/oapi/form/schema"), paths);
} finally {
gateway.stop(0);
}
}
}