知识卡片
消息扩展只增不替换
既有消费者仍在使用旧消息,而新需求要求增加属性或改变字段形态时,需要让新旧表示并存。
扩展响应时保留旧字段:标量phoneNumber变为多值需求时新增phoneNumbers,name拆分时保留name并增givenName、familyName。预留名称—值集合可容纳附加属性,外层message容器可并列承载新旧表示。输入也应兼容旧格式;严格拒绝未知字段的客户端校验仍会破坏这些扩展策略。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 超媒体接口设计 · 查看原书依据
An effective approach to modifying response bodies that are already in production is to adopt the “Don’t Change It, Add It” rule (see “Don’t change it, add it”). That means you leave any existing elements in place and simply include new elements in the current response body. You can also design your response formats to support a simple name-value-pair collection where you can place additional new properties (of any type, including arrays). See the following examples for details.
参考来源
- 位置:《RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)》第03章《超媒体接口设计》(来源项目 book-sources;源文件:extracted/RESTful Web API Patterns and Practices Cookbook Connecting and Orchestrating Microservices and Distributed Data (Mike Amundsen)/_epub-src/OEBPS/ch03.xhtml;小节:3.10)
- 结论依据:原文以扩展响应时保留旧字段:标量phoneNumber变为多值需求时新增phoneNumbers,name拆分时保留name并增givenName、familyName的机制或场景为依据;同小节余文补充本卡所列条件,按2022年原书语境整理。
- 原始内容:An effective approach to modifying response bodies that are already in production is to adopt the “Don’t Change It, Add It” rule (see “Don’t change it, add it”). That means you leave any existing elements in place and simply include new elements in the current response body. You can also design your response formats to support a simple name-value-pair collection where you can place additional new properties (of any type, including arrays). See the following examples for details.