json definitions 关键字的架构用法

json schema usage of definitions keyword

任何人都可以帮助我使用 json 模式中的定义。我浏览了他们的 website 并没有得到太多信息。

任何帮助都是值得的。

the definitions keyword is a standardized placeholder in which you can define inline subschemas to be used in a schema.

换句话说,定义关键字 定义了 子模式,您可以在模式的其他地方引用它们。也许这是一个更简单的例子:

"properties": {
    "cars": {
        "type": "object",
        "oneOf": [
            { "$ref": "#/definitions/ford" },
            { "$ref": "#/definitions/bmw" },
            { "$ref": "#/definitions/audi" }
        ]
    }
},
"definitions": {
    "ford": {
        "origin": "USA"
     },
    "bmw": {
        "origin": "Germany"
    },
    "audi": {
        "origin": "Germany"
    }
}

definitions 下,您 定义 子模式,例如 ford,您可以在其他地方使用 "$ref": "#definitions/ford".