2013-07-27 3 views
0

아래 나는 모든 옵션 태그 actionType 요소 값 ID가 "SAVECONTACT"JSON 스키마 요소 옵션은

내가 잘 모릅니다 만 진실해야 언급 종속성이 내 JSON 스키마

입니다 이러한 의존성을

을 구현하기 위해이

{ 
    "type": "object", 
    "properties": { 
     "userId": { 
      "type": "string", 
      "optional": true 
     }, 
     "groupId": { 
      "type": "string", 
      "optional": true 
     }, 
     "socialMediaContacts": { 
      "type": "array", 
      "items": { 
       "type": "object", 
       "properties": { 
        "smContactId": { 
         "type":"string" 
        }, 
        "actionType": { 
         "type":"string", 
         "enum" : ["SAVECONTACT", "DELETECONTACT", "SAVEGROUP", "DELETEGROUP"] 
        }, 
        "contactLastName": { 
         "type":"string", 
         "optional": true 
        }, 
        "contactFirstName": { 
         "type":"string", 
         "optional": true 
        }, 
        "nickName": { 
         "type":"string", 
         "optional": true 
        }, 
        "contactType": { 
         "type":"string", 
         "enum" : ["SM", "REG"], 
         "optional": true 
        }, 
        "mediaSource": { 
         "type":"string", 
         "enum" : ["FB", "FS", "TW"], 
         "optional": true 
        }, 
        "socialMediaHandle": { 
         "type":"string", 
         "optional": true 
        }, 
        "email": { 
         "type":"string", 
         "optional": true 
        }, 
        "phone": { 
         "type":"string", 
         "optional": true 
        } 
       } 
      } 
     } 
    } 
} 

답변

0

좀 도와주십시오 나는 당신의 문제에 대한 해결책이 동일한 AP를 사용하는 것 같아요 절차 that suggested in this question.

먼저 사용자 정의 태그 "선택 사항"대신 "필수"를 사용하는 표준 방법을 사용합니다.

{ 
"type": "object", 
"properties": { 
    "userId": { 
     "type": "string", 
     "optional": true 
    }, 
    "groupId": { 
     "type": "string", 
     "optional": true 
    }, 
    "socialMediaContacts": { 
     "type": "array", 
     "allOf": 
     { 
      "properties": { 
        "smContactId": {"type":"string"}, 
        "actionType": {"enum" : ["SAVECONTACT", "DELETECONTACT", "SAVEGROUP", "DELETEGROUP"]}, 
        "contactLastName": {"type":"string"}, 
        "contactFirstName": {"type":"string"}, 
        "nickName": {"type":"string"}, 
        "contactType": {"type":"string","enum" : ["SM", "REG"]}, 
        "mediaSource": {"type":"string","enum" : ["FB", "FS", "TW"]}, 
        "socialMediaHandle": {"type":"string"}, 
        "email": {"type":"string"}, 
        "phone": {"type":"string"} 
       }, 
       "required": ["actionType","smContactId"], 
       "additionalProperties": False 
      }, 
     "oneOf": [ 
      { "$ref": "#/definitions/savecontact" }, 
      { "$ref": "#/definitions/otheroperations" } 
     ] 
    } 
}, 
"definitions": { 
    "savecontact": { 
     "properties": { 
      "actionType": { "enum": [ "SAVECONTACT" ] }, 

     }, 
     "required": ["contactLastName","contactFirstName", etc. etc.], 
    }, 
    "otheroperations": { 
     properties": { 
      "actionType": {"enum" : ["DELETECONTACT", "SAVEGROUP", "DELETEGROUP"]} 
     } 
    } 
} 

}

나는 문제의 전체 맥락을 잘 모르겠지만, 아마도 더 의미가있을 수 있습니다 작업 당 하나의 스키마를 가지고 : 당신이 초안 4 검사기가있는 경우 다음과 같이 뭔가 일할 수 .

1

이러한 상황을 처리하려면 "oneOf"이 필요합니다.

{ 
    "type": "object", 
    ... /* other constraints */ 
    "oneOf": [ 
     { 
      "properties": { 
       "actionType": {"enum": ["SAVECONTACT"]} 
      }, 
      "required": [... all the properties ...] 
     } 
     { 
      "properties": { 
       "actionType": {"enum": ["DELETECONTACT", ...]} 
      }, 
      "required": [/* empty */] 
     } 
    ] 
} 
"SAVECONTACT"및 비 "SAVECONTACT"-

기본적으로, 당신은 각 상황에 대한 스키마를 만들