src/actions.js
function getDefaults (value, path, model, resolveRef) {
  const schema = findSchema(model, path, resolveRef)
  const schemaDefault = _.clone(schema.default)

  if (model.type === 'object') {
    const subSchemaDefaults = {}
    _.forIn(schema.properties, function (subSchema, propName) {
      const defaults = getDefaults(
        value && value[propName],
        null,
        subSchema,
        resolveRef
      )
      if (defaults !== undefined) {
        subSchemaDefaults[propName] = defaults
      }
    })

    if (Object.keys(subSchemaDefaults).length > 0) {
      return _.defaults({}, schemaDefault, subSchemaDefaults)
    }
    return schemaDefault
  } else if (value !== undefined) {
    return value
  }
  return schemaDefault
}
function getDefaults (value, path, model, resolveRef) {
  const schema = findSchema(model, path, resolveRef)
  const schemaDefault = _.clone(schema.default)

  if (model.type === 'object') {
    const subSchemaDefaults = {}
    _.forIn(schema.properties, function (subSchema, propName) {
      const defaults = getDefaults(
        value && value[propName],
        null,
        subSchema,
        resolveRef
      )
      if (defaults !== undefined) {
        subSchemaDefaults[propName] = defaults
      }
    })

    if (Object.keys(subSchemaDefaults).length > 0) {
      return _.defaults({}, schemaDefault, subSchemaDefaults)
    }
    return schemaDefault
  } else if (value !== undefined) {
    return value
  }
  return schemaDefault
}
function getDefaults ( value , path , model , resolveRef ) { const schema = findSchema ( model , path , resolveRef ) const schemaDefault = _ . clone ( schema . default ) if ( model . type === 'object' ) { const subSchemaDefaults = { } _ . forIn ( schema . properties , function ( subSchema , propName ) { const defaults = getDefaults ( value && value [ propName ] , null , subSchema , resolveRef ) if ( defaults !== undefined ) { subSchemaDefaults [ propName ] = defaults } } ) if ( Object . keys ( subSchemaDefaults ) . length > 0 ) { return _ . defaults ( { } , schemaDefault , subSchemaDefaults ) } return schemaDefault } else if ( value !== undefined ) { return value } return schemaDefault }
Returns the value with defaults provided by the schema
@param {Object} value - a complex object/array (the bunsen form value)
@param {String} path - path to retrieve the sub schema of the model given
@param {Object} model - bunsen model schema
@param {Function} resolveRef - function to resolve references
@returns {Object} the value with defaults applied
Returns the value with defaults provided by the schema