2016-08-31 10 views
3

私は別のファイルの文字列の列挙を持ち、それを私のスキーマから参照したい場合のためにJSON schemaを作成しようとしています。どうすればそれを達成できますか?Json Schema - 参照を使用して列挙を使用する

サンプル・スキーマ:

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "object", 
    "properties": { 
     "card": { 
      "type": "object", 
      "properties": { 
       "id": { 
        "type": "integer" 
       }, 
       "value": { 
        "type": "string", 
        "enum": {"$ref" : "reference to a file having list of enums"} 
        //I want to refer to a specific enum array (say value1's array) 
       } 
      } 
     } 
    }, 
    "required": [ 
     "card" 
    ] 
} 

列挙型ファイルは次のようである:

{ 
"value1": [..], 
"value2": [..] 
.... 
} 

答えて

2

$refのみスキーマを参照するために使用されるべきです。だから、あなたはこのようなことをすることができます。

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "type": "object", 
    "properties": { 
     "card": { 
      "type": "object", 
      "properties": { 
       "id": { "type": "integer" }, 
       "value": { "$ref" : "/schemas/valueEnum.json" } 
      } 
     } 
    }, 
    "required": ["card"] 
} 

/schemas/valueEnum.json

{ "enum": ["foo", "bar"] } 
関連する問題