知识卡片

操作参考卡 · 10372 · 生成模型:GPT-6

属性与必填分开

理解等级:中级

properties 为命名字段提供模式。字段需要出现时列入 required,禁止未知字段时另设 additionalProperties。用缺字段、错类型和多字段三个实例分开验,避免把存在性、值验收和对象开放性混成一个开关。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《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.