知识卡片
数组缺失与空数组
如果 roles 不在 required,只写 minItems: 1 会拒绝空数组但允许省略。只写 required 则允许传空数组。两条同时写才能要求调用者明确提交至少一个角色。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Improving input validation with advanced JSON Schema 19.3 Updating PetSitter schemas · 查看原书依据
Warning Be careful not to confuse an empty array with a nonexistent array (we talked about this earlier in the book regarding collection endpoints). If you set minItems to 1 but don’t include your array in required, both a nonexistent array (missing
参考来源
- 位置:《Designing APIs with Swagger and OpenAPI》第19章《Improving input validation with advanced JSON Schema》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch19.htm,阅读块 114)
- 结论依据:书中用 minItems 和 required 的交叉组合说明三种状态。
- 原始内容:Warning Be careful not to confuse an empty array with a nonexistent array (we talked about this earlier in the book regarding collection endpoints). If you set minItems to 1 but don’t include your array in required, both a nonexistent array (missing