2011-12-21 10 views
7

क्या सामान्य-जेएस यूटिल में जेएसओएन स्कीमा सत्यापन संदर्भों का समर्थन करता है? मैं https://github.com/kriszyp/commonjs-utils/blob/master/json-schema.jsक्या सामान्य-जेएस यूटिल में जेएसओएन स्कीमा सत्यापन संदर्भों का समर्थन करता है?

साथ ऐसा नहीं कर सकते मैं कोड निम्नलिखित की कोशिश की:

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

मैं आगे जाना है और बाहर संदर्भ के साथ मेरी स्कीमा तैयार कर सकते हैं, लेकिन यह करता है, तो यह संभव है पता करने के लिए अच्छा होगा। संदर्भ के विषय में एक प्रतिलिपि चिपकाया पोस्ट मैं json मंच पर डाल

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

यहाँ है:

उत्तर

19

मैं नहीं जानता, लेकिन आपके रेफरी गलत हो रहा है, "$" को दूर पर हस्ताक्षर यानी

मसौदे 03 के अनुसार यहां एक आईडी निर्दिष्ट करने और इसे कहीं से संदर्भित करने के बारे में समझा गया है। अगर कुछ गलत है तो कृपया टिप्पणी करें। मामले निम्न में लिखे गए हैं: ए। यूरी जहां से मैं स्कीमा बी पुनर्प्राप्त करता हूं। स्कीमा सी मिला। इस स्कीमा को कैसे देखें

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#"} 
संबंधित मुद्दे