* [resolve and compile the references ($ref)] * @this Ajv * @param {Function} compile reference to schema compilation funciton (localCompile) * @param {Object} root object with information about the root schema for the current schema * @param {String} ref reference to resolve * @return {Ob
(compile, root, ref)
| 46765 | * @return {Object|Function} schema object (if the schema can be inlined) or validation function |
| 46766 | */ |
| 46767 | function resolve(compile, root, ref) { |
| 46768 | /* jshint validthis: true */ |
| 46769 | var refVal = this._refs[ref]; |
| 46770 | if (typeof refVal == 'string') { |
| 46771 | if (this._refs[refVal]) refVal = this._refs[refVal]; |
| 46772 | else return resolve.call(this, compile, root, refVal); |
| 46773 | } |
| 46774 | |
| 46775 | refVal = refVal || this._schemas[ref]; |
| 46776 | if (refVal instanceof SchemaObject) { |
| 46777 | return inlineRef(refVal.schema, this._opts.inlineRefs) |
| 46778 | ? refVal.schema |
| 46779 | : refVal.validate || this._compile(refVal); |
| 46780 | } |
| 46781 | |
| 46782 | var res = resolveSchema.call(this, root, ref); |
| 46783 | var schema, v, baseId; |
| 46784 | if (res) { |
| 46785 | schema = res.schema; |
| 46786 | root = res.root; |
| 46787 | baseId = res.baseId; |
| 46788 | } |
| 46789 | |
| 46790 | if (schema instanceof SchemaObject) { |
| 46791 | v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId); |
| 46792 | } else if (schema !== undefined) { |
| 46793 | v = inlineRef(schema, this._opts.inlineRefs) |
| 46794 | ? schema |
| 46795 | : compile.call(this, schema, root, undefined, baseId); |
| 46796 | } |
| 46797 | |
| 46798 | return v; |
| 46799 | } |
| 46800 | |
| 46801 | |
| 46802 | /** |
no test coverage detected