lib/defaults.js
function(schema, definitions) {

    if (typeof schema['default'] !== 'undefined') {

      return schema['default'];

    } else if (typeof schema.allOf !== 'undefined') {

      var mergedItem = mergeAllOf(schema.allOf, definitions);
      return defaults(mergedItem, definitions);

    } else if (typeof schema.$ref !== 'undefined') {

      var reference = getLocalRef(schema.$ref, definitions);
      return defaults(reference, definitions);

    } else if (schema.type === 'object') {

      if (!schema.properties) { return {}; }

      for (var key in schema.properties) {
        if (schema.properties.hasOwnProperty(key)) {
          schema.properties[key] = defaults(schema.properties[key], definitions);

          if (typeof schema.properties[key] === 'undefined') {
            delete schema.properties[key];
          }
        }
      }

      return schema.properties;

    } else if (schema.type === 'array') {

      if (!schema.items) { return []; }

      // minimum item count
      var ct = schema.minItems || 0;
      // tuple-typed arrays
      if (schema.items.constructor === Array) {
        var values = schema.items.map(function (item) {
          return defaults(item, definitions);
        });
        // remove undefined items at the end (unless required by minItems)
        for (var i = values.length - 1; i >= 0; i--) {
          if (typeof values[i] !== 'undefined') {
            break;
          }
          if (i + 1 > ct) {
            values.pop();
          }
        }
        return values;
      }
      // object-typed arrays
      var value = defaults(schema.items, definitions);
      if (typeof value === 'undefined') {
        return [];
      } else {
        var values = [];
        for (var i = 0; i < Math.max(1, ct); i++) {
          values.push(cloneJSON(value));
        }
        return values;
      }

    }

  }
function(schema, definitions) {

    if (typeof schema['default'] !== 'undefined') {

      return schema['default'];

    } else if (typeof schema.allOf !== 'undefined') {

      var mergedItem = mergeAllOf(schema.allOf, definitions);
      return defaults(mergedItem, definitions);

    } else if (typeof schema.$ref !== 'undefined') {

      var reference = getLocalRef(schema.$ref, definitions);
      return defaults(reference, definitions);

    } else if (schema.type === 'object') {

      if (!schema.properties) { return {}; }

      for (var key in schema.properties) {
        if (schema.properties.hasOwnProperty(key)) {
          schema.properties[key] = defaults(schema.properties[key], definitions);

          if (typeof schema.properties[key] === 'undefined') {
            delete schema.properties[key];
          }
        }
      }

      return schema.properties;

    } else if (schema.type === 'array') {

      if (!schema.items) { return []; }

      // minimum item count
      var ct = schema.minItems || 0;
      // tuple-typed arrays
      if (schema.items.constructor === Array) {
        var values = schema.items.map(function (item) {
          return defaults(item, definitions);
        });
        // remove undefined items at the end (unless required by minItems)
        for (var i = values.length - 1; i >= 0; i--) {
          if (typeof values[i] !== 'undefined') {
            break;
          }
          if (i + 1 > ct) {
            values.pop();
          }
        }
        return values;
      }
      // object-typed arrays
      var value = defaults(schema.items, definitions);
      if (typeof value === 'undefined') {
        return [];
      } else {
        var values = [];
        for (var i = 0; i < Math.max(1, ct); i++) {
          values.push(cloneJSON(value));
        }
        return values;
      }

    }

  }
function ( schema , definitions ) { if ( typeof schema [ 'default' ] !== 'undefined' ) { return schema [ 'default' ] ; } else if ( typeof schema . allOf !== 'undefined' ) { var mergedItem = mergeAllOf ( schema . allOf , definitions ) ; return defaults ( mergedItem , definitions ) ; } else if ( typeof schema . $ref !== 'undefined' ) { var reference = getLocalRef ( schema . $ref , definitions ) ; return defaults ( reference , definitions ) ; } else if ( schema . type === 'object' ) { if ( ! schema . properties ) { return { } ; } for ( var key in schema . properties ) { if ( schema . properties . hasOwnProperty ( key ) ) { schema . properties [ key ] = defaults ( schema . properties [ key ] , definitions ) ; if ( typeof schema . properties [ key ] === 'undefined' ) { delete schema . properties [ key ] ; } } } return schema . properties ; } else if ( schema . type === 'array' ) { if ( ! schema . items ) { return [ ] ; } // minimum item count var ct = schema . minItems || 0 ; // tuple-typed arrays if ( schema . items . constructor === Array ) { var values = schema . items . map ( function ( item ) { return defaults ( item , definitions ) ; } ) ; // remove undefined items at the end (unless required by minItems) for ( var i = values . length - 1 ; i >= 0 ; i -- ) { if ( typeof values [ i ] !== 'undefined' ) { break ; } if ( i + 1 > ct ) { values . pop ( ) ; } } return values ; } // object-typed arrays var value = defaults ( schema . items , definitions ) ; if ( typeof value === 'undefined' ) { return [ ] ; } else { var values = [ ] ; for ( var i = 0 ; i < Math . max ( 1 , ct ) ; i ++ ) { values . push ( cloneJSON ( value ) ) ; } return values ; } } }
returns a object that built with default values from json schema

@param {Object} schema
@param {Object} definitions
@return {Object}
returns a object that built with default values from json schema