用于验证一个参数的多种类型和值的 json 模式 [英] json schema to validate multiple types and values for one parameter
本文介绍了用于验证一个参数的多种类型和值的 json 模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个问题:我尝试编写一个 json 模式来验证以下对象:
Please help me with this: I try to write a json schema to validate the following object:
json 对象:
{"param":value}
可能的值:'all',[任何整数的数组]
Possible values: 'all', [array of any integers]
因此它是一个简单的 json 对象,其中包含一个变量,该变量可以是字符串 'all' 或任何整数数组 [].
So it is a simple json object which contain one variable that could be string 'all', or array of any integers [].
我试过了,但它在 json 模式验证器中不起作用:
I tried this but it doesn't work in json schema validator:
{
"type": ["string","array"],
"items": { "oneOf": [
"all",
{ "type": "integer" }
]
}
}
谢谢.
推荐答案
对于draft4,这个模式应该可以工作
For draft4 this schema should work
{
"type": "object",
"properties": {
"param": {
"oneOf": [
{
"enum": ["all"]
},
{
"type": "array",
"items": {"type": "integer"}
}
]
}
},
"additionalProperties": false,
"required": ["param"]
}
oneOf
的值应该是对象列表,关键字 enum
允许与值进行比较.
Value of oneOf
should be list of objects and keyword enum
allows to compare with the value.
这篇关于用于验证一个参数的多种类型和值的 json 模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文