2011-12-21 3 views
7

common-js utils에서 JSON 스키마 유효성 검사가 참조를 지원합니까? 나는 다음 코드를 시도 https://github.com/kriszyp/commonjs-utils/blob/master/json-schema.jscommon-js utils에서 JSON Schema 유효성 검사가 참조를 지원합니까?

이 작업을 수행 할 수 없습니다

{ 
    "type" : "object", 
    "required" : true, 
    "properties" : { 
    "id" : { 
     "type" : "number", 
     "required" : true 
    }, 
    "related" : { 
     "type" : "array", 
     "required" : true, 
     "items" : {"$ref": "$#"} 
    } 
    } 
} 

내가 가서 밖으로 참조 내 스키마를 준비하지만, 가능하다면 알고 좋을 수 있습니다.

답변

19
모르겠어요

는, 그러나 당신의 심판이 잘못된 것 같다 은 "$"를 제거 즉, 서명 : 여기

"items" : {"$ref": "#"} 

은 내가 JSON 포럼에 넣어 복사 붙여 게시물을 참조 관련된 :

03 초안에 따르면 여기에 ID를 지정하고 어디에서든지 참조하는 것에 대해 이해하고 있습니다. 잘못된 것이 있으면 의견을 말하십시오. 사례는 다음과 같이 작성되었습니다. a. 내가 스키마를 검색 할 곳의 URL. b. 스키마는 입니다. c. 이 스키마를 참조하는 방법

1. A schema without any "id" property 
I fetch : http://someSite.com/somePath 
I get : { } 
I can ref it : {"$ref":"http://someSite.com/somePath#"} 

2. Same absolute id and uri path 
I fetch : http://someSite.com/somePath 
I get : {"id":"http://someSite.com/somePath#"} 
I can ref it : {"$ref":"http://someSite.com/somePath#"} 

3. Different absolute id and path 
I fetch : http://someSite.com/somePath 
I get : {"id":"http://anotherSite.com/anotherPath#"} 
I can ref it : {"$ref":"http://anotherSite.com/anotherPath#"} 

4. Relative - a fragment 
I fetch : http://someSite.com/somePath 
I get : {"id":"#something"} 
I can ref it : {"$ref":"http://someSite.com/somePath#something"} 

5. Relative path and fragment 
I fetch : http://someSite.com/somePath 
I get : {"id":"/oneMore/path#something"} 
I can ref it : {"$ref":"http://someSite.com/somePath/oneMore/path#something"} 

6. Relative path from file 
I fetch : file:///someFolder/someFile 
I get : {"id":"/oneMore/path#something"} 
I can ref it : {"$ref":"file:///someFolder/someFile/oneMore/path#something"} 

7. Inner schema (sub schema) with id "#subschema" (no id for the main schema) 
I fetch : http://someSite.com/somePath 
I get : {"properties" : { "aKeyName" : { "id":"#subschema" }}} 
I can ref it : {"$ref":"http://someSite.com/somePath#subschema"} 

8. Inner schema (sub schema) with id "#subschema" 
I fetch : http://someSite.com/somePath 
I get : { {"id":"#mainSchema"}, "properties" : { "aKeyName" : { "id":"#subschema" }} } 
I can ref it : {"$ref":"http://someSite.com/somePath#subschema"} 
I can also do: {"$ref":"http://someSite.com/somePath#mainSchema/properties/aKeyName"} 

9. Inner schema (within the property under the "aKeyName") but no id at all 
I fetch : http://someSite.com/somePath 
I get : { "properties" : { "aKeyName" : { }} } 
can ref it: {"$ref":"http://someSite.com/somePath#/properties/aKeyName"} 

10. Inner schema (sub schema) with a main custom absolute uri" 
I fetch : http://someSite.com/somePath 
I get : { {"id":"scheme://something"}, "properties" : { "aKeyName" : { "id":"#subschema" }} } 
I can ref it : {"$ref":"scheme://something#subschema"} 
I can also do: {"$ref":"scheme://something#/properties/aKeyName"} 

11. Inner schema with it's own absolute uri" 
I fetch : http://someSite.com/somePath 
I get : { {"id":"#main"}, "properties" : { "aKeyName" : { "id":"http://domain.com/subSchema" }} } 
I can ref it : {"$ref":"http://domain.com/subSchema#"}