58

商品の配列用のjsonファイルのスキーマを作りたいです。

json スキーマは次のようになります。

{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product set",
"type": "array",
"items": {
    "title": "Product",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "number"
        },
        "name": {
            "type": "string"
        },
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        },
        "tags": {
            "type": "array",
            "items": {
                "type": "string"
            },
            "minItems": 1,
            "uniqueItems": true
        },
        "dimensions": {
            "type": "object",
            "properties": {
                "length": {"type": "number"},
                "width": {"type": "number"},
                "height": {"type": "number"}
            },
            "required": ["length", "width", "height"]
        },
        "warehouseLocation": {
            "description": "Coordinates of the warehouse with the product",
            "$ref": "http://json-schema.org/geo"
        }
    },
    "required": ["id", "name", "price"]
}
}

配列には、少なくとも 1 つの項目が含まれている必要があります。配列の最小値を定義するにはどうすればよいですか?

最小定義を追加する必要がありますか?

4

3 に答える 3

8

いいえ、少なくともワーキングドラフトを見るとminimum、配列ではなく数値にのみ適用されます。

5.1. 数値インスタンス (数値および整数) の検証キーワード
...
5.1.3. 最小および排他的Minimum

したがって、配列の min/maxItems に慣れる必要があります。

于 2013-05-17T18:51:41.283 に答える