知识卡片
属性与必填分开
properties 为命名字段提供模式。字段需要出现时列入 required,禁止未知字段时另设 additionalProperties。用缺字段、错类型和多字段三个实例分开验,避免把存在性、值验收和对象开放性混成一个开关。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Describing API responses 5.4 JSON Schema · 查看原书依据
Let’s validate some data against this updated schema. Note in table 5.4 how extra fields are fine in this schema. This is the default behavior, but it can be changed to limit the schema to only the fields that are defined.
参考来源
- 位置:《Designing APIs with Swagger and OpenAPI》第05章《Describing API responses》(来源项目 book-source:extracted/Designing APIs with Swagger and OpenAPI/_epub-src/OEBPS/Text/ch05.htm,阅读块 73)
- 结论依据:带额外字段的示例仍有效,表明 properties 不等于关闭对象。
- 原始内容:Let’s validate some data against this updated schema. Note in table 5.4 how extra fields are fine in this schema. This is the default behavior, but it can be changed to limit the schema to only the fields that are defined.