知识卡片

操作参考卡 · 3487.i.6.a · 生成模型:GPT-6

用引用复用模式

理解等级:中级

在 components.schemas 给共享模式命名,再从实际使用位置用 $ref 指向它。例如 ‘#/components/schemas/User’ 指向文档根下的 User。只声明组件不会主动使任何操作使用它。[[共享模式避免约束漂移]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《Designing APIs with Swagger and OpenAPI》第10章《Creating an API design using OpenAPI》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch10.htm,阅读块 57) - 结论依据:正文列出请求、响应与另一 Schema 都可通过 ref 引用公共模式。 - 原始内容:Once we have created common schemas in the components section of our OpenAPI file, we can use the $ref keyword to add references to them. Those references can be used in requests, responses, and even other schemas.