2017-02-03 1 views
1

:JSON 스키마가 필요한 노드 I는 다음과 같은 방식으로 JSON 스키마를 만들려고 해요

{ 
    "$schema": "http://json-schema.org/schema#", 
    "title": "Layout", 
    "description": "The layout created by the user", 
    "type": "object", 
    "definitions": { 
    "stdAttribute": { 
     "type": "object", 
     "properties": { 
     "attributeValue": { 
      "type": "object" 
     }, 
     "attributeName": { 
      "type": "string" 
     } 
     } 
    }, 
    "stdItem": { 
     "type": "object", 
     "required" : ["stdAttributes"], 
     "properties": { 
     "stdType": { 
      "enum": [ 
      "CONTAINER", 
      "TEXT", 
      "TEXTAREA", 
      "BUTTON", 
      "LABEL", 
      "IMAGE", 
      "MARCIMAGE", 
      "DATA", 
      "SELECT", 
      "TABLE" 
      ] 
     }, 
     "stdAttributes": { 
      "type": "array", 
      "items": { 
      "$ref": "#/definitions/stdAttribute" 
      } 
     }, 
     "children": { 
      "type": "array", 
      "items": { 
      "$ref": "#/definitions/stdItem" 
      } 
     } 
     } 
    } 
    }, 
    "properties": { 
    "layoutItem": { 
     "$ref": "#/definitions/stdItem" 
    } 
    } 
} 

나는 그것에 대하여 다음과 같은 JSON의 유효성을 검사하고 있습니다 :

{ 
    "layoutItem": { 
    "stdItem": { 
     "stdType": "CONTAINER", 
     "stdAttributes": [], 
     "children": [] 
    } 
    } 
} 

문제를 "stdAtrributes"노드를 필요에 따라 "stdItem"으로 지정하고 유효성 검사기에서이를 확인할 수 없기 때문에 java 유효성 검사기를 실행할 때 오류가 발생합니다.

속성 내에 필요한 배열을 정의하려고 시도했지만 스키마가 무효화됩니다. 내가 "stdAttributes"외부 "stdItem"를 넣으면

, 그것을 작동합니다.

"stdItem"에 대해이 요청을 어떻게 정의 할 수 있는지 아는 사람 있습니까?

답변

0

스키마의 문제점은 스키마 #/definitions/stdItem에 따라 layoutItem 값을 유효하게 설정하는 것입니다.

는하지만 (데이터)를 찾고 싶어 같은 stdItem 속성 객체를 정의하지 않습니다이 스키마, 그것은 특성 stdType, stdAttributeschildren와 객체를 정의하고 특성 stdAttributes이 존재해야합니다. 데이터를 저장하기위한

{ 
    "layoutItem": { 
    "stdType": "CONTAINER", 
    "stdAttributes": [], 
    "children": [] 
    } 
} 

스키마가 있어야한다 : 즉, 그것은 다음과 같은 데이터에 대한 스키마입니다 그것은 작동

{ 
    ... 
    "definitions": { 
    ... 
    "stdItem": { 
     "type": "object", 
     "required" : ["stdItem"], 
     "properties": { 
     "stdItem": { 
      "type": "object", 
      "required" : ["stdAttributes"], 
      "properties": { 
      "stdType": { ... }, 
      "stdAttributes": { ... }, 
      "children": { ... } 
      } 
     } 
     } 
    } 
    }, 
    ... 
} 
+0

은! 고맙습니다. – Jeyvison