2017-02-06 1 views
1

을 검증 할 수 없습니다 :JSON 스키마 내가 다음 JSON 스키마 코딩있어 필수 속성

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

검사기가 오류가 없지만 스키마에 말한다 : 나는 다음과 같은 데이터를 설정

{ 
    "$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" 
      }, 
      "minItems": 1 
     }, 
     "children": { 
      "type": "array", 
      "items": { 
      "$ref": "#/definitions/stdItem" 
      } 
     } 
     } 
    } 
    } 
} 

나는 "StdAttribute""StdAttributtes"에 minItems와 ref를 사용하고 있습니다.

기본 스키마에서이 속성을 정의하려고했지만 유효성 검사기에서 동일한 것을 말합니다.

"StdAttributes"에서 항목의 유형과 수를 어떻게 검증해야합니까?

Java Validator를 사용하고 있습니다.

답변

1

최상위 수준에 properties 특성이 누락되었습니다. 지금 스키마가 유효성을 검증하는 유일한 방법은 데이터가 객체라는 것입니다. definitions은 자체적으로 유효성을 검사하지 않습니다. 스키마에서 참조 할 수있는 스키마를 보유 할 수있는 곳입니다. 다음은 예상 결과를 얻기 위해 스키마의 루트에 추가해야하는 최소값입니다.

"properties": { 
    "stdItem": { "$ref": "#/definitions/stdItem" } 
}