2016-11-07 1 views

답변

0

내 현재 솔루션 : 나는 jsonschema을 사용하고

{ 
    "type": "object", 
    "oneOf": [ 
    {"$ref": "#/definitions/0"}, 
    {"$ref": "#/definitions/1"}, 
    ], 
    "definitions": { 
    "0": { 
     "properties": { 
     "num": {"enum": [0]}, 
     "a": {"type": "string"} 
     }, 
     "required": ["num", "a"] 
    }, 
    "1": { 
     "properties": { 
     "num": {"enum": [1]}, 
     "b": {"type": "string"} 
     }, 
     "required": ["num", "b"] 
    } 
    } 
} 

, 그것은 is not exactly on from <#definitions/0>을 반환합니다. 그건 내가 원하는 것이 아니야. 세부 사항에 대한 메시지를 반환 할 수 있기를 바랍니다 (예 : a 필요).

0

개선 된 버전 :

{ 
    "type": "object", 
    "properties": { 
    "num": { "type": "integer" }, 
    "a": { "type": "string" }, 
    "b": { "type": "string" } 
    } 
    "required": [ "num" ], 
    "dependencies": { 
    "a": { 
     "properties": { 
     "num": { 
      "enum": [0] 
     } 
     } 
    }, 
    "b": { 
     "properties": { 
     "num": { 
      "enum": [1] 
     } 
     } 
    } 
    } 
}