AnyOf 与类型数组

AnyOf vs type array

以下两个 JSON 模式验证之间是否存在差异,或者它们是否验证相同的数据结构?

SomeProperty
{
    "type": ["integer","string"]
}
SomeProperty
{
    "anyOf": [
         {
            "type": "integer"
         },
         {
             "type": "string"
         }
     ]
}

它们是等价的!

type

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

String values MUST be one of the six primitive types ("null", "boolean", "object", "array", "number", or "string"), or "integer" which matches any number with a zero fractional part.

An instance validates if and only if the instance is in any of the sets listed for this keyword.

https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-validation-01#section-6.1.1

注意最后一节“...在任何...中”