test(lastleg): validate shared appointment contract references

This commit is contained in:
2026-10-16 18:14:37 +08:00
parent fee0268391
commit 4348296daf
@@ -66,6 +66,16 @@ class FleetTripApiContractTest {
.contains("UNIQUE KEY uk_fleet_trip_history_version (trip_id,record_version)");
}
/** 预约批次引用解析到正式海外契约,同时继续拒绝未知文件和缺失定义。 */
@Test void appointmentReferencesResolveWithoutAllowingUnknownContracts() {
verifyRefs(Map.of("$ref", "overseas-business-v1.yaml#/components/schemas/DispatchBatchReference"), Map.of());
assertThatThrownBy(() -> verifyRefs(Map.of("$ref", "unknown-v1.yaml#/components/schemas/DispatchBatchReference"), Map.of()))
.isInstanceOf(AssertionError.class);
assertThatThrownBy(() -> verifyRefs(Map.of("$ref", "overseas-business-v1.yaml#/components/schemas/MissingDispatchBatch"), Map.of()))
.isInstanceOf(AssertionError.class);
}
/** 校验允许的跨文件合同引用和 JSON Pointer 所指对象均存在。 */
private static void verifyRefs(Object node, Map<String, Object> root) {
if (node instanceof Map<?, ?> map) {
if (map.get("$ref") instanceof String reference) {
@@ -74,7 +84,7 @@ class FleetTripApiContractTest {
if(!reference.startsWith("#/")) {
String[] parts=reference.split("#",2);
assertThat(parts).hasSize(2);
assertThat(Path.of(parts[0]).getFileName().toString()).isIn("fleet-quote-candidates-v1.yaml","fleet-trips-v1.yaml","fleet-capacity-offers-v1.yaml");
assertThat(Path.of(parts[0]).getFileName().toString()).isIn("fleet-quote-candidates-v1.yaml","fleet-trips-v1.yaml","fleet-capacity-offers-v1.yaml","overseas-business-v1.yaml");
try { value=new Yaml().load(Files.readString(Path.of("src/main/resources/openapi",parts[0]))); }
catch(java.io.IOException error) { throw new java.io.UncheckedIOException(error); }
pointer="#"+parts[1];