2017-06-19 8 views
0

私はJsonSchema(v4)の作成に取り組んでいます。 私は、その親から別のプロパティの値に基づいて1つのプロパティを要求するようにしようとしています。jsonスキーマ - 別のフィールド値に基づいてフィールドが必要です

  • ユーザー
    • サブタイプ
    • アドレス

子供

  • 住所
    • LINE1
    • LINE2
    • にcompanyName(ユーザーのサブタイプが会社である場合は必須)

はどのようにこれを行うことができますか? 私は今、このような何かを持っている...

{ 
"User": { 
    "title": "User", 
    "type": "object", 
    "id": "#User", 
    "properties": { 
    "subtype": { 
     "type": "string" 
    }, 
    "address": { 
     "$ref": "Address" 
    } 
    } 
} 


"Address": { 
    "title": "Address", 
    "type": "object", 
    "id": "#Address", 
    "properties": { 
    "line1": { 
     "type": "string" 
    }, 
    "line2": { 
     "type": "string" 
    }, 
    "companyName": { 
     "type": "string" 
    } 
    }, 
    "required": ["line1", "line2"] 
} 
} 

サブタイプは、任意の文字列であるので、異なるサブタイプの完全なリストはできません。

答えて

0

これをあなたのユーザースキーマに追加してください。基本的には、「サブタイプ」は「会社」ではなく「住所」には「会社名」が必要です。

"anyOf": [ 
    { 
    "not": { 
     "properties": { 
     "subtype": { "enum": ["company"] } 
     } 
    } 
    }, 
    { 
    "properties": { 
     "address": { 
     "required": ["companyName"] 
     } 
    } 
    } 
] 
+0

非常にありがとうございます! – neljamin

関連する問題