Skip to content

Commit

Permalink
Issue garycourt#53 - Fix lookup to correctly find the base node
Browse files Browse the repository at this point in the history
  • Loading branch information
kewisch committed Oct 25, 2012
1 parent 33b0532 commit baf6302
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions lib/jsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,10 +828,10 @@ var exports = exports || this,
}

if (this._env._options["validateReferences"] && this._refs) {
if (this._refs["describedby"] && !this._env.findSchema(this._refs["describedby"], parentSchema)) {
if (this._refs["describedby"] && !this._env.findSchema(this._refs["describedby"])) {
report.addError(this, this._schema, "{describedby}", "Unknown schema reference", this._refs["describedby"]);
}
if (this._refs["full"] && !this._env.findSchema(this._refs["full"], parentSchema)) {
if (this._refs["full"] && !this._env.findSchema(this._refs["full"])) {
report.addError(this, this._schema, "{full}", "Unknown schema reference", this._refs["full"]);
}
}
Expand Down Expand Up @@ -1073,19 +1073,25 @@ var exports = exports || this,
* @returns {JSONSchema|undefined} The request schema, or <code>undefined</code> if not found
*/

Environment.prototype.findSchema = function (uri, parentSchema) {
var furi = formatURI(uri);
var schema = null;
if (furi in this._schemas) {
schema = this._schemas[furi];
} else if (parentSchema) {
var fragment = furi.substr(furi.indexOf("#"));
var targetElem = traversePointer(parentSchema.getValue(), fragment);
if (targetElem) {
schema = this.createSchema(targetElem, null);
}
}
return schema;
Environment.prototype.findSchema = function (uri) {
var furi = formatURI(uri);
var schema = null;
if (furi in this._schemas) {
schema = this._schemas[furi];
} else {
var base = furi.substr(0, furi.indexOf("#"));
if (formatURI(base) != furi) {
var baseSchema = this.findSchema(base);
if (baseSchema) {
var fragment = furi.substr(base.length);
var targetElem = traversePointer(baseSchema.getValue(), fragment);
if (targetElem) {
schema = this.createSchema(targetElem, null, furi);
}
}
}
}
return schema;
};

/**
Expand Down

0 comments on commit baf6302

Please sign in to comment.