Json 架构条件验证配置 - 不支持的关键字:["const"]]
Json schema conditional validation configuration - Unsupported keyword(s): ["const"]]
我想在我的架构中设置条件验证。我在 上看到了一个例子。
我有一个类似的设置,我想验证字段 public 是否设置为字符串“public”。如果它设置为“public”,那么我想制作字段 description、attachmentUrl 和 tags 需要。如果字段未设置为“public”,则不需要此字段。
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Update todo",
"type": "object",
"properties": {
"public": {
"type": "string"
},
"description": {
"type": "string",
"minLength": 3
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"minItems": 1
},
"attachmentUrl": {
"type": "string"
}
},
"anyOf": [
{
"not": {
"properties": {
"public": { "const": "public" }
},
"required": ["public"]
}
},
{ "required": ["description", "tags", "attachmentUrl"] }
],
"additionalProperties": false
}
但是,当我尝试那样部署它时,出现以下错误:
Invalid model specified: Validation Result: warnings : [], errors :
[Invalid model schema specified. Unsupported keyword(s): ["const"]]
直到 06 草案才添加“const”关键字。您应该升级到至少支持该版本的实现。
否则,您可以使用具有单个值的“枚举”:"enum": ["public"]
我想在我的架构中设置条件验证。我在
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Update todo",
"type": "object",
"properties": {
"public": {
"type": "string"
},
"description": {
"type": "string",
"minLength": 3
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true,
"minItems": 1
},
"attachmentUrl": {
"type": "string"
}
},
"anyOf": [
{
"not": {
"properties": {
"public": { "const": "public" }
},
"required": ["public"]
}
},
{ "required": ["description", "tags", "attachmentUrl"] }
],
"additionalProperties": false
}
但是,当我尝试那样部署它时,出现以下错误:
Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified. Unsupported keyword(s): ["const"]]
直到 06 草案才添加“const”关键字。您应该升级到至少支持该版本的实现。
否则,您可以使用具有单个值的“枚举”:"enum": ["public"]