<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>oasdiff on </title>
    <link>/tags/oasdiff/</link>
    <description>Recent content in oasdiff on </description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Sat, 25 Apr 2026 10:00:00 +0800</lastBuildDate><atom:link href="/tags/oasdiff/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>API 与 event contract 兼容性保障：工具机制与正确用法</title>
      <link>/posts/api-event-contract-compatibility-qa-2026/</link>
      <pubDate>Sat, 25 Apr 2026 10:00:00 +0800</pubDate>
      
      <guid>/posts/api-event-contract-compatibility-qa-2026/</guid>
      <description>📦 本文基于的完整项目源码：meirongdev/shop
上一篇 微服务 contract 兼容性的五层防线：从 ArchUnit 到 japicmp 讨论了如何用 ArchUnit、japicmp、WireMock 和运行时 Deprecation 头构建基础安全带。本文聚焦更具体的问题：BFF 对外的 API、BFF→MS 和 MS→MS 的内部 API、以及 Kafka 事件，各自应该用什么工具保障 contract 兼容性，这些工具的工作机制是什么。
一、两类 contract，两种保障方式 Q：BFF 对外暴露的 API 和 BFF→MS、MS→MS 之间的内部 API，兼容性的保障方式应该一样吗？
在我的实践中不太一样。主要原因在于 source of truth 不同。
BFF 对外的 API（前端、移动端、三方调用方）采用的是 API-first 方式：先有 OpenAPI YAML，生产者的 controller 实现这份 YAML，消费者根据这份 YAML 生成客户端代码或手写调用。在这条链路里，YAML 就是权威来源。保障兼容性就是保障 YAML 文件本身不引入 breaking change。
BFF→MS 和 MS→MS 之间采用的是 code-first 方式：Java record 是 source of truth，没有提前写 spec，序列化层（Jackson）从 record 推导出 JSON 结构。保障兼容性就是保障 Java record 的 JSON 表现形式不引入 breaking change。</description>
    </item>
    
  </channel>
</rss>
