code: function resolveSchemaRefs(val, validator, _root) {
  
      _root = _root || val;
      resolve(val, '', val);
      return val;
  
      /*
       * @param {mixed} val
       * @param {String|Int} key
       * @param {Object|Array} object
       */
      function resolve(val, key, object) {
          if (_.isPlainObject(val)) {
              if (   val.hasOwnProperty('$ref')
                  && typeof val.$ref === 'string'
              ) {
  
                  var resolved;
  
                  if (val.$ref.indexOf('#') === 0) {
                      let path = _.compact(val.$ref.slice(1).split('/'));
                      if (_.has(_root, path)) {
                          resolved = _.cloneDeep(_.get(_root, path));
                          _.set(object, key, resolved);
  
                      }
                  } else if ((resolved = validator.getSchema(val.$ref))) {
                      resolved = _.cloneDeep(resolved.schema);
                      _.set(object, key, resolved);
                  }
  
                  do {
                      resolve(resolved, key, object);
                  }
                  while (   _.isPlainObject(object[key])
                           && object[key].hasOwnProperty('$ref')
                  );
              } else {
                  _.forOwn(val, resolve);
              }
          } else if (val instanceof Array) {
              val.forEach(resolve);
          }
          //can not return anything because of the lodash.forOwn
      }
  }
docs: dereferences releative $refs and internal references to other ajv validator schemas
  @function resolveSchemaRefs
  @memberof Utils
  @static
  @param {Object|Array} val - value
  @param {Ajv} validator
  @param {Object|Array} [_root] - initial value
  @return {Object}