← 返回刚才阅读的位置

知识卡片

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

可为空与可缺失

理解等级:中级

字段已出现且其值为 null,和整个字段缺失是不同实例。OpenAPI 3.0 可在同一 Schema Object 中用 type: string 与 nullable: true 接纳明确的 null;属性的 required 继续控制它是否必须出现。

这张卡片看不懂?

已有反馈 · 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,阅读块 184) - 结论依据:示例对匿名作者使用 nullable,区分其他可接受的数据类型。 - 原始内容:In OpenAPI, multiple types like this are not supported (as of OpenAPI 3.0.x, at least). But to make allowance for the very common use case of having a schema be some value or null, the spec has the nullable keyword.