小编sen*_*asi的帖子

在JSON模式中定义枚举数组的正确方法

我想用JSON模式数组来描述,该数组应包含零个或多个预定义值.为简单起见,让我们这些可能的值:one,twothree.

正确的数组(应该通过验证):

[]
["one", "one"]
["one", "three"]
Run Code Online (Sandbox Code Playgroud)

不正确:

["four"]
Run Code Online (Sandbox Code Playgroud)

现在,我知道"enum"应该使用该属性,但我找不到相关信息放在哪里.

选项A(下"items"):

{
    "type": "array",
    "items": {
        "type": "string",
        "enum": ["one", "two", "three"]
    }
}
Run Code Online (Sandbox Code Playgroud)

选项B:

{
    "type": "array",
    "items": {
        "type": "string"
    },
    "enum": ["one", "two", "three"]
}
Run Code Online (Sandbox Code Playgroud)

arrays enums json jsonschema

49
推荐指数
2
解决办法
4万
查看次数

标签 统计

arrays ×1

enums ×1

json ×1

jsonschema ×1