forked from garycourt/JSV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added self referencing support to links.
- Loading branch information
Showing
5 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* @fileOverview Implementation of the first revision of the JSON Schema specification draft. | ||
* @author <a href="mailto:[email protected]">Gary Court</a> | ||
* @version 1.3 | ||
* @version 1.4 | ||
* @see http://github.com/garycourt/JSV | ||
*/ | ||
|
||
|
@@ -799,7 +799,12 @@ | |
var instance = arg[1], | ||
href = link["href"]; | ||
href = href.replace(/\{(.+)\}/g, function (str, p1, offset, s) { | ||
var value = instance.getValueOfProperty(p1); | ||
var value; | ||
if (p1 === "-this") { | ||
value = instance.getValue(); | ||
} else { | ||
value = instance.getValueOfProperty(p1); | ||
} | ||
return value !== undefined ? String(value) : ""; | ||
}); | ||
return href ? JSV.formatURI(instance.resolveURI(href)) : href; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* @fileOverview Implementation of the second revision of the JSON Schema specification draft. | ||
* @author <a href="mailto:[email protected]">Gary Court</a> | ||
* @version 1.3 | ||
* @version 1.4 | ||
* @see http://github.com/garycourt/JSV | ||
*/ | ||
|
||
|
@@ -823,7 +823,12 @@ | |
var instance = arg[1], | ||
href = link["href"]; | ||
href = href.replace(/\{(.+)\}/g, function (str, p1, offset, s) { | ||
var value = instance.getValueOfProperty(p1); | ||
var value; | ||
if (p1 === "-this") { | ||
value = instance.getValue(); | ||
} else { | ||
value = instance.getValueOfProperty(p1); | ||
} | ||
return value !== undefined ? String(value) : ""; | ||
}); | ||
return href ? JSV.formatURI(instance.resolveURI(href)) : href; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* @fileOverview Implementation of the third revision of the JSON Schema specification draft. | ||
* @author <a href="mailto:[email protected]">Gary Court</a> | ||
* @version 0.9 | ||
* @version 1.0 | ||
* @see http://github.com/garycourt/JSV | ||
*/ | ||
|
||
|
@@ -811,7 +811,8 @@ | |
var links, | ||
linkSchemaURI = self.getValueOfProperty("items")["$ref"], | ||
linkSchema = self.getEnvironment().findSchema(linkSchemaURI), | ||
linkParser = linkSchema && linkSchema.getValueOfProperty("parser"); | ||
linkParser = linkSchema && linkSchema.getValueOfProperty("parser"), | ||
selfReferenceVariable; | ||
arg = JSV.toArray(arg); | ||
|
||
if (typeof linkParser === "function") { | ||
|
@@ -829,19 +830,27 @@ | |
} | ||
|
||
if (arg[1]) { | ||
selfReferenceVariable = self.getValueOfProperty("selfReferenceVariable"); | ||
links = JSV.mapArray(links, function (link) { | ||
var instance = arg[1], | ||
href = link["href"]; | ||
href = href.replace(/\{(.+)\}/g, function (str, p1, offset, s) { | ||
var value = instance.getValueOfProperty(p1); | ||
var value; | ||
if (p1 === selfReferenceVariable) { | ||
value = instance.getValue(); | ||
} else { | ||
value = instance.getValueOfProperty(p1); | ||
} | ||
return value !== undefined ? String(value) : ""; | ||
}); | ||
return href ? JSV.formatURI(instance.resolveURI(href)) : href; | ||
}); | ||
} | ||
|
||
return links; | ||
} | ||
}, | ||
|
||
"selfReferenceVariable" : "-this" | ||
}, | ||
|
||
"fragmentResolution" : { | ||
|
@@ -1451,6 +1460,10 @@ | |
"id" : "http://json-schema.org/draft-03/hyper-schema#", | ||
|
||
"properties" : { | ||
"links" : { | ||
"selfReferenceVariable" : "@" | ||
}, | ||
|
||
"root" : { | ||
"deprecated" : true | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters