知识卡片
路径参数必填
URL 模板 /reviews/{reviewId} 缺少 ID 就无法组成特定资源的地址。声明 name 与占位符相同、in 为 path,并写 required: true。查询参数负责路径之外的额外输入,可按需要设为可选。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Creating resources 6.4 Describing GET /reviews/{reviewId} with a path parameter · 查看原书依据
Note that besides in being set to path, the only extra field we require (compared to query parameters) is the required field. A path parameter cannot be optional, according to the OpenAPI spec.
参考来源
- 位置:《Designing APIs with Swagger and OpenAPI》第06章《Creating resources》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch06.htm,阅读块 150)
- 结论依据:原文说明路径参数的 required 不允许取 false。
- 原始内容:Note that besides in being set to path, the only extra field we require (compared to query parameters) is the required field. A path parameter cannot be optional, according to the OpenAPI spec.