JSON模式中的对象或字符串数​​组

时间:2017-04-24 15:21:58

标签: json jsonschema

努力寻找明确的答案。

我正在编写一些JSON模式验证,并希望验证传入的有效负载是字符串数组(与模式匹配)还是对象数组。

例如......

{
    "src" : [ 
        {
            "serviceName" : "svc1",
            "filename" : "ABC000000001234567.tar"
        },
        {
            "serviceName" : "svc2",
            "filename" : "DEF000000001234567.tar"
        }
    ]  
}

...或...

{
    "src" : [
        "file://svc1/ABC000000001234567.tar",
        "file://svc2/DEF000000001234567.tar"
    ]
}

我现在有这个,但它没有工作......

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "title": "My schema",
    "additionalProperties": false,
    "properties": {
        "src": {
            "type": "array",
            "additionalItems": false,
            "items": {
                "oneOf": [
                    {
                        "$ref": "#/definitions/svcUrl"
                    },
                    {
                        "$ref": "#/definitions/svcObj"
                    }
                ]
            }
        }
    },
    "definitions": {
        "svcUrl": {
            "type": "string",
            "pattern": "^file\\:\\/\\/",
            "required": []
        },
        "svcObj": {
            "type": "object",
            "properties": {
                "serviceName": {
                    "type": "string"
                },
                "filename": {
                    "type": "string"
                }
            },
            "required": [
                "RequiredProperty",
                "filename",
                "serviceName"
            ]
        }
    }
}

有人可以帮我解决这个问题吗?

0 个答案:

没有答案