Correct JSON Schema for an array of items of different type

后端 未结 5 1329
渐次进展
渐次进展 2020-12-16 10:56

I have an unordered array of JSON items. According to the specification http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.5 the json schema below will only vali

5条回答
  •  情书的邮戳
    2020-12-16 11:17

    For anyone stuck with the draft 3 schema. There is a "Type" keyword that is equivalent to the "anyOf" in draft 4:

    So you can use

    {
        "fooBar" : {
            "type" : "array",
            "items" : {
                "type" : [{
                        "type" : "object",
                        "properties" : {
                            "foo" : {                           
                                "type" : "string"
                            }
                        }
                    }, {
                        "type" : "object",
                        "properties" : {
                            "bar" : {
                                "type" : "string"
                            }
                        }
                    }
                ]
            }
        }
    }
    

提交回复
热议问题