[英]How to use "oneOf" in this schema?
我想要 A 或 B,但不能同时拥有(互斥)。
我必须使用 Draft 3 中可用的任何内容,即使它在顶部显示为 4。 原因是,当使用数组作为“必需”时,它会抛出一个错误,即它无法将数组转换为 boolean。如果我删除 arrays 而没有放置我正在使用草稿 4 [Newtonsoft.Json.Schema.Extensions]: :IsValid 不验证。 它无意中返回“真”。
是的,我必须使用过时的 Newtonsoft。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "",
"type": "object",
"additionalProperties": false,
"properties": {
"SearchCriteria": {
"type": "array",
"uniqueItems": true,
"minItems": 1,
"required": true,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"A": {
"type": "string",
"minLength": 1,
"pattern": "^[^\\s]*$"
},
"B": {
"type": "array",
"items": {
"type": "string",
"minLength": 1,
"pattern": "^[^\\s]*$",
"enum": ["One", "Two"]
},
"minItems": 1
},
"C": {
"type": "string",
"required": true,
"minLength": 2
},
"D": {
"type": "array",
"required": true,
"items": {
"type": "string"
},
"minItems": 1,
"uniqueItems": true
}
}
}
}
}
}
草案 3不支持评论中提到的@dbc之类的OneOf
或任何类似内容。
[Newtonsoft.Json.Schema.JsonSchema]
使用 draft 3 prase JSON 文件。 因此,为什么它忽略OneOf
并抛出"required"
是数组的错误。 在草案 3 中, "required"
只能是boolean
。
为了克服这个问题,使用[Newtonsoft.Json.Schema.JSchema]
将 Schema 解析为字符串,使用 [ [Newtonsoft.Json.Linq.JToken]
将 JSON 解析为字符串,并使用[Newtonsoft.Json.Schema.SchemaExtensions]
Newtonsoft.Json] 解析为 validExchema.Schema.Schema [Newtonsoft.Json.Schema.Extensions]
的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.