鉴于以下OpenAPI定义
Person:
required:
- id
type: object
properties:
id:
type: string
以下哪些对象是有效的?只有A还是A和B都有效?
A. {"id": ""}
B. {"id": null}
C. {}
这归结为一个问题,即“required = true”是指“非空的值”还是“必须存在的属性”。
https://json-schema-validator.herokuapp.com/上的JSON模式验证器表示2.无效,因为null
不满足type: string
约束。请注意,它不是因为id
为null而抱怨,而是因为null
不是字符串。但是,这对于OpenAPI / Swagger有多重要?
null
类型,可将可空模式定义为{"type": ["string", "null"]}
。但OpenAPI不支持type: null
,而是使用nullable
属性。 - HelenallOf
+required
列表。示例 - Helen