diff --git a/lib/ajv.js b/lib/ajv.js index 726e4d8fa..c6452a324 100644 --- a/lib/ajv.js +++ b/lib/ajv.js @@ -158,9 +158,9 @@ function Ajv(opts) { else throw new Error(message); } - resolve.ids.call(self, schema); + var localRefs = resolve.ids.call(self, schema); - var validate = compileSchema.call(self, schema); + var validate = compileSchema.call(self, schema, undefined, localRefs); if (id[0] != '#') self._refs[id] = validate; self._cache.put(str, validate); diff --git a/lib/compile/index.js b/lib/compile/index.js index b5214b994..07d215eb5 100644 --- a/lib/compile/index.js +++ b/lib/compile/index.js @@ -12,7 +12,7 @@ var RULES = require('./rules') module.exports = compile; -function compile(schema, root) { +function compile(schema, root, localRefs) { var self = this , refVal = [ undefined ] , refs = {}; @@ -75,6 +75,12 @@ function compile(schema, root) { } var v = resolve.call(self, compile, root, ref); if (v) return addLocalRef(ref, v); + + var localSchema = localRefs[ref]; + if (localSchema) { + var v = compile.call(self, localSchema, root, localRefs); + if (v) return addLocalRef(ref, v); + } } function addLocalRef(ref, v) { diff --git a/lib/compile/resolve.js b/lib/compile/resolve.js index 00e5ceb9e..97151be03 100644 --- a/lib/compile/resolve.js +++ b/lib/compile/resolve.js @@ -117,29 +117,36 @@ function resolveUrl(baseId, id) { function resolveIds(schema) { var id = normalizeId(schema.id); + var localRefs = {}; _resolveIds.call(this, schema, getFullPath(id, false), id); -} - - -function _resolveIds(schema, fullPath, baseId) { - if (Array.isArray(schema)) - for (var i=0; i