【发布时间】:2018-01-16 10:43:42
【问题描述】:
鉴于以下 OpenAPI 定义,以下哪些对象是有效的。只有 1. 或 1. 和 2.?
Person:
required:
- id
type: object
properties:
id:
type: string
{"id": ""}{"id": null}{}
这归结为“required = true”是指“非空值”还是“必须存在属性”的问题。
https://json-schema-validator.herokuapp.com/ 的 JSON 模式验证器表示 2. 无效,因为 null 不满足 type: string 约束。请注意,它不会抱怨因为id 为空,而是因为null 不是字符串。但这与 OpenAPI/Swagger 有多大关系?
【问题讨论】: