dist/scripts/scripts.js
function instantiate(schema, options) {
  options = options || {};

  /**
   * Visits each sub-object using recursion.
   * If it reaches a primitive, instantiate it.
   * @param obj - The object that represents the schema.
   * @param name - The name of the current object.
   * @param data - The instance data that represents the current object.
   */
  function visit(obj, name, data) {
    if (!obj) {
      return;
    }

    var i;
    var type = getObjectType(obj);

    // We want non-primitives objects (primitive === object w/o properties).
    if (type === 'object' && obj.properties) {
      data[name] = data[name] || { };

      // Visit each property.
      for (var property in obj.properties) {
        if (obj.properties.hasOwnProperty(property)) {
          if (shouldVisit(property, obj, options)) {
            visit(obj.properties[property], property, data[name]);
          }
        }
      }
    } else if (obj.allOf) {
      for (i = 0; i < obj.allOf.length; i++) {
        visit(obj.allOf[i], name, data);
      }
    } else if (obj.$ref) {
      obj = findDefinition(schema, obj.$ref);
      visit(obj, name, data);
    } else if (type === 'array') {
      data[name] = [];
      var len = 0;
      if (obj.minItems || obj.minItems > 0) {
        len = obj.minItems;
      }

      // Instantiate 'len' items.
      for (i = 0; i < len; i++) {
        visit(obj.items, i, data[name]);
      }
    } else if (isEnum(obj)) {
      data[name] = instantiateEnum(obj);
    } else if (isPrimitive(obj)) {
      data[name] = instantiatePrimitive(obj);
    }
  }

  var data = {};
  visit(schema, 'kek', data);
  return data['kek'];
}
function instantiate(schema, options) {
  options = options || {};

  /**
   * Visits each sub-object using recursion.
   * If it reaches a primitive, instantiate it.
   * @param obj - The object that represents the schema.
   * @param name - The name of the current object.
   * @param data - The instance data that represents the current object.
   */
  function visit(obj, name, data) {
    if (!obj) {
      return;
    }

    var i;
    var type = getObjectType(obj);

    // We want non-primitives objects (primitive === object w/o properties).
    if (type === 'object' && obj.properties) {
      data[name] = data[name] || { };

      // Visit each property.
      for (var property in obj.properties) {
        if (obj.properties.hasOwnProperty(property)) {
          if (shouldVisit(property, obj, options)) {
            visit(obj.properties[property], property, data[name]);
          }
        }
      }
    } else if (obj.allOf) {
      for (i = 0; i < obj.allOf.length; i++) {
        visit(obj.allOf[i], name, data);
      }
    } else if (obj.$ref) {
      obj = findDefinition(schema, obj.$ref);
      visit(obj, name, data);
    } else if (type === 'array') {
      data[name] = [];
      var len = 0;
      if (obj.minItems || obj.minItems > 0) {
        len = obj.minItems;
      }

      // Instantiate 'len' items.
      for (i = 0; i < len; i++) {
        visit(obj.items, i, data[name]);
      }
    } else if (isEnum(obj)) {
      data[name] = instantiateEnum(obj);
    } else if (isPrimitive(obj)) {
      data[name] = instantiatePrimitive(obj);
    }
  }

  var data = {};
  visit(schema, 'kek', data);
  return data['kek'];
}
function instantiate ( schema , options ) { options = options || { } ; /**
   * Visits each sub-object using recursion.
   * If it reaches a primitive, instantiate it.
   * @param obj - The object that represents the schema.
   * @param name - The name of the current object.
   * @param data - The instance data that represents the current object.
   */ function visit ( obj , name , data ) { if ( ! obj ) { return ; } var i ; var type = getObjectType ( obj ) ; // We want non-primitives objects (primitive === object w/o properties). if ( type === 'object' && obj . properties ) { data [ name ] = data [ name ] || { } ; // Visit each property. for ( var property in obj . properties ) { if ( obj . properties . hasOwnProperty ( property ) ) { if ( shouldVisit ( property , obj , options ) ) { visit ( obj . properties [ property ] , property , data [ name ] ) ; } } } } else if ( obj . allOf ) { for ( i = 0 ; i < obj . allOf . length ; i ++ ) { visit ( obj . allOf [ i ] , name , data ) ; } } else if ( obj . $ref ) { obj = findDefinition ( schema , obj . $ref ) ; visit ( obj , name , data ) ; } else if ( type === 'array' ) { data [ name ] = [ ] ; var len = 0 ; if ( obj . minItems || obj . minItems > 0 ) { len = obj . minItems ; } // Instantiate 'len' items. for ( i = 0 ; i < len ; i ++ ) { visit ( obj . items , i , data [ name ] ) ; } } else if ( isEnum ( obj ) ) { data [ name ] = instantiateEnum ( obj ) ; } else if ( isPrimitive ( obj ) ) { data [ name ] = instantiatePrimitive ( obj ) ; } } var data = { } ; visit ( schema , 'kek' , data ) ; return data [ 'kek' ] ; }
The main function.
Calls sub-objects recursively, depth first, using the sub-function 'visit'.
@param schema - The schema to instantiate.
@returns {*}
The main function . Calls sub - objects recursively depth first using the sub - function visit .