【问题标题】:Is "description" a valid "property" for an object in a JSON schema?“描述”是 JSON 模式中对象的有效“属性”吗?
【发布时间】:2013-05-02 04:53:23
【问题描述】:

假设我正在编写一个 JSON 模式。 “类型”是“对象”。在对象的“属性”中包含名为“描述”的属性是否合法?我问是因为“描述”是 JSON 模式中的关键字。

示例:在此示例中,我为表示葡萄酒年份的 JSON 对象提供了一个简单的模式。我指定了四个属性:三个必需属性(房子、年份和葡萄品种)和一个可选属性,名为“description”。

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Wine vintage",
    "description": "JSON schema for wine vintages",
    "type": "object",
    "properties": {
        "house": {
            "description": "The name of the house that made the wine",
            "type": "string"
        },
        "year": {
            "description": "The year in which the wine was made",
            "type": "integer"
        },
        "varieties": {
            "description": "The grape varieties used to make the wine",
            "type": "array",
            "items": {
                "type": "string",
                "minItems": 1,
                "uniqueItems": true
            }
        }
        "description": {
            "description": "A description of the wine's taste and character; a tasting note",
            "type": "string"
        }
    },
    "required": ["house", "year", "varieties"]
}

【问题讨论】:

    标签: json keyword jsonschema


    【解决方案1】:

    "properties" 中的键从不具有任何特殊含义。你可以在那里使用任何东西:"id""description",甚至是"$ref"

    模式关键字只有在直接在模式对象中时才具有特殊含义。

    【讨论】:

      【解决方案2】:

      我认为这是合法的。我在spec 中看不到任何明确禁止定义与模式关键字相同的对象属性名称的内容。 (此外,如果确实如此,“id”、“type”和“items”等有用且常见的词也将被禁止用作属性名称。)

      【讨论】:

        猜你喜欢
        • 2016-02-07
        • 1970-01-01
        • 2021-03-09
        • 1970-01-01
        • 2017-08-08
        • 1970-01-01
        • 1970-01-01
        • 2016-08-04
        • 1970-01-01
        相关资源
        最近更新 更多