maxItems/minItems 可以在 JSON 模式中与 $ref 一起使用吗

Can maxItems/minItems be used with a $ref in a JSON schema

给定 JSON 模式,在定义部分包含以下内容:

"phoneNumber": {
            "type": "object",
            "properties": {
                "countryCode": {
                    "type": "number"
                    },
                "areaCode": {
                    "type": "number"
                    },
                "number": {
                    "type": "number"
                    },
                "extension": {
                    "type": "number"
                    },
                "service": {
                    "type": "string",
                    "enum": ["Voice", "Fax", "Data"]
                    },
                "class": {
                    "type": "string",
                    "enum": ["Switchboard", "Direct", "PA", "Mobile"]
                    }
                }
            }

如果我想使用 $ref 在别处包含 phoneNumber 并希望 JSON 验证它是否包含多次出现的 phoneNumber,我可以使用 maxItems/minItems:

"person": {
    "type": "object",
    "properties": {
        "name": {
            "type": "string"
            },
        "phoneNumber": {
            "$ref": "#/definitions/phoneNumber"
            //can I use maxItems/minItems here?
            }
        }
    }

我可以在这里使用 maxItems 和 minItems 吗,还是我必须像下面这样做才能验证:

"phoneNumber": {
    "allOf": { "$ref": "#/definitions/phoneNumber" },
    "maxItems": 4
}

$ref 必须独立。您使用 allOf 确定的选项是最好的方法。

Any members other than "$ref" in a JSON Reference object SHALL be ignored.