知识卡片

普通读书笔记卡 · 3487.e

路径参数可供多方法共用

理解等级:中级

同一 URL 路径下若有 GET、PUT、DELETE 等多个方法,可以在路径层声明共用的路径参数。订单路径里的 {order_id} 因此只定义一次,方法共享其必填和 UUID 格式约束,减少重复描述与各方法间的契约偏差。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    原书出处

    参考来源

    - 位置:《Microservice APIs》第 5 章《Documenting REST APIs with OpenAPI》(源文件:_epub-src/OEBPS/Text/05.htm) - 结论依据:原文明确说把 order_id 直接定义在 URL 路径下,使参数适用于该路径所有 HTTP 方法,并示例规定必填、string 和 UUID 格式。 - 原始内容:In OpenAPI, path parameters are represented between curly braces. We specify that the order_id parameter is a string with a UUID format (a long, random string often used as an ID). ... We define the URL path parameter directly under the URL path to make sure it applies to all HTTP methods.