知识卡片
请求体声明载荷结构
OpenAPI 把请求消息体写在操作的 requestBody 中:required 表示是否必须携带,content 按媒体类型列出可接收格式,再用 schema 限定字段、枚举与默认值。这样 POST 或 PUT 的载荷要求既能供人阅读,也能供工具校验。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Microservice APIs》第 5 章《Documenting REST APIs with OpenAPI》(源文件:_epub-src/OEBPS/Text/05.htm)
- 结论依据:原文以订单创建端点示例指出 requestBody、required、content、application/json 与 schema 的分工,并列出枚举和默认值约束。
- 原始内容:We define request payloads under the content property of the method’s requestBody property . We can specify payloads in different formats. In this case, we allow data only in JSON format, which has a media type definition of application/json . ... we define an enumeration for the size property, which constrains the accepted values to small , medium , and big . Finally, we also provide a default value of 1 for the quantity property