在JSON模式中定义枚举数组的正确方法 [英] Correct way to define array of enums in JSON schema
本文介绍了在JSON模式中定义枚举数组的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用JSON模式数组进行描述,该数组应该包含零个或多个预定义值.为简单起见,让我们使用以下可能的值:one
,two
和three
.
I want to describe with JSON schema array, which should consist of zero or more predefined values. To make it simple, let's have these possible values: one
, two
and three
.
正确的数组(应通过验证):
Correct arrays (should pass validation):
[]
["one", "one"]
["one", "three"]
不正确:
["four"]
现在,我知道应该使用"enum"
属性,但是找不到在哪里放置相关信息.
Now, I know the "enum"
property should be used, but I can't find relevant information where to put it.
选项A(在"items"
下):
{
"type": "array",
"items": {
"type": "string",
"enum": ["one", "two", "three"]
}
}
选项B:
{
"type": "array",
"items": {
"type": "string"
},
"enum": ["one", "two", "three"]
}
推荐答案
选项A正确且满足您的要求.
Option A is correct and satisfy your requirements.
{
"type": "array",
"items": {
"type": "string",
"enum": ["one", "two", "three"]
}
}
这篇关于在JSON模式中定义枚举数组的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文