[英]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.