知识卡片

普通读书笔记卡 · 2313.e.5.f.10.b.3.i.2.e.1.b.1 · 生成模型:未记录

网关行为也是契约

理解等级:中级

公开 API 的契约应覆盖调用方经过网关、策略引擎和应用服务实际看到的请求和响应。即使控制器完全按 OpenAPI 生成,网关也可能因认证或限流提前返回自己的错误对象。如果网关的公开错误格式与服务错误不同,可以在公开规格中准确记录,或让网关采用统一错误格式。

网关若进行显著转换,生成后端代码应基于后端所接收的接口形态,外部规格用于描述入口。用经过网关的符合性检查校验真实状态码、媒体类型和响应模式。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 通过代码与定义生成促进遵约 6.2 Generating code from OpenAPI · 查看原书依据

      There are challenges with generating API server code from the API definition. One is that API responses may not come from your API service, but from a component that sits in front of your service. So you need to configure the relevant components to generate responses in the required format. For example, the API gateway can have the responsibility of authenticating the consumer’s API key and can send a response for key authentication failures (a 401 error).

    参考来源

    - 位置:《Automating API Delivery APIOps with OpenAPI》《第 06 章 通过代码与定义生成促进遵约》(6.2 Generating code from OpenAPI;来源项目 book-source,extracted/Automating API Delivery APIOps with OpenAPI/_epub-src/OEBPS/Text/chapter-6.xhtml#p119) - 结论依据:说明接口可见响应可能由网关而非服务产生。 - 原始内容:There are challenges with generating API server code from the API definition. One is that API responses may not come from your API service, but from a component that sits in front of your service. So you need to configure the relevant components to generate responses in the required format. For example, the API gateway can have the responsibility of authenticating the consumer’s API key and can send a response for key authentication failures (a 401 error).