小编jav*_*dev的帖子

当元素是可选的时,如何在json模式中定义choice元素?

------------ Josn schema -----------

{
    "type": "object",
    "properties": {
        "street_address": {
            "type": "string"
        },
        "city": {
            "type": "string"
        },
        "state": {
            "type": "string"
        }
    },
    "required": [
        "street_address"
    ],
    "additionalProperties": false
}
Run Code Online (Sandbox Code Playgroud)

在上面的模式中,我想在城市和州之间创建一个选择.无论是城市还是州都可以来json.所以json下面会无效

{
    "street_address": "abc",
    "city": "anv",
    "state": "opi"
}
Run Code Online (Sandbox Code Playgroud)

以下一个应该是有效的

{
    "street_address": "abc"
}
Run Code Online (Sandbox Code Playgroud)

要么

{
    "street_address": "abc",
    "city": "anv"
}
Run Code Online (Sandbox Code Playgroud)

要么

{
    "street_address": "abc",
    "state": "opi"
}
Run Code Online (Sandbox Code Playgroud)

有人可以帮我修改上面的架构来完成目标.

json jsonschema

8
推荐指数
2
解决办法
9137
查看次数

标签 统计

json ×1

jsonschema ×1