2017-01-06 3 views
1

: 나는 "B"요소에 대한 새 스키마 파일을 작성하여 참조 할 지금JSON 스키마 심판 다른 파일

{ 
    "a": { 
    "c": "test" 
    } 
} 

:이 예를 확인할 수

{ 
    "$schema": "http://json-schema.org/draft-04/schema#", 
    "b": { 
    "type": "object", 
    "properties": { 
     "c": { 
     "type": "string" 
     } 
    } 
    }, 
    "type": "object", 
    "properties": { 
    "a": { 
     "$ref": "#/b" 
    } 
    } 
} 

내 첫 번째 스키마에서. 어떻게해야합니까? 나는 많은 것을 시도하지만 항상 jsonspec.reference.exceptions.NotFound : u'b.json '을 등록하지 않습니다.

답변

0

몇 시간의 인터넷 검색 및 다양한 문서 읽기 후에 나는 "$ref" : "file:..."을 사용하여 2 개의 json-schema를 작성할 수있게되었습니다.

john-doe.json:

{ 
    "first_name": "john", 
    "last_name": "doe", 
    "age": 42, 
    "address": { 
    "street_address": "foo street 42", 
    "city": "baklavastan", 
    "state": "foobar" 
    "foo": 42 
    } 
} 

을 그리고 내 파일 시스템의 같은 디렉토리에 살고 이 JSON 스키마 파일을 가지고 :

내 예를 들어 데이터는 다음과 같습니다.

customer.json

{ 
    "type": "object", 
    "properties": { 
    "first_name": { "type": "string" }, 
    "last_name": { "type": "string" }, 
    "age" :  { "type" : "integer" }, 
    "address" : { "$ref" : "file:address.json#" } 
    }, 
    "required": ["first_name", "last_name", "age", "address"], 
    "additionalProperties": false 
} 

address.json 내가

그것을 (자바 json-schema-validation 라이브러리의 래퍼입니다) 라이브러리 scjsv를 사용 Clojure의 스키마에 대해 유효성을 검사 할 수 있어요

{ 
    "type": "object", 
    "properties": { 
    "street_address": { "type": "string" }, 
    "city":   { "type": "string" }, 
    "state":   { "type": "string" } 
    }, 
    "required": ["street_address", "city", "state"], 
    "additionalProperties": false 
} 

에 대해 다음과 같은 유효성 검사 오류 (clojure edn에서)를 제공합니다.예 :

{ :level "error", 
    :schema {:loadingURI "file:address.json#", :pointer ""}, 
    :instance {:pointer "/address"}, 
    :domain "validation", 
    :keyword "additionalProperties", 
    :message 
    "object instance has properties which are not allowed by the schema: [\"foo\"]", 
    :unwanted ["foo"] }