archive/v1/client/method.js
function getFields(def, obj) {
		var a = {};
		
		// if not an object, return the value
		if (!_.isObject(obj)) {
			return obj;
		}
		
		// check for type override
		var defType = _.get(obj, 'attributes.xsi:type') || _.get(obj, 'attributes.type');
		defType     = defType ? defType.replace(/^vim25\:/i, '') : null;

		// if there is a type override and it is a valid type, set the def to that type
		// and add the type to the attributes
		if (defType && _.has(_client.types, defType)) {
			def = _client.types[defType]();
			a.attributes = {
				'xsi:type': defType
			};
		}
		
		// loop through each field in the type definition and look for fields
		// that were supplied by the user
		_.forEach(def, function(v, k) {
			if (_.has(obj, k)) {
				if (Array.isArray(obj[k])) {
					a[k] = _.map(obj[k], function(o) {
						return getFields(v, o);
					});
				}
				else if (_.isObject(v) && _.isObject(obj[k])) {
					a[k] = getFields(v, obj[k]);
				}
				else {
					a[k] = obj[k];
				}
			}
		});
		
		// return the new arguments object
		return a;
	}
function getFields(def, obj) {
		var a = {};
		
		// if not an object, return the value
		if (!_.isObject(obj)) {
			return obj;
		}
		
		// check for type override
		var defType = _.get(obj, 'attributes.xsi:type') || _.get(obj, 'attributes.type');
		defType     = defType ? defType.replace(/^vim25\:/i, '') : null;

		// if there is a type override and it is a valid type, set the def to that type
		// and add the type to the attributes
		if (defType && _.has(_client.types, defType)) {
			def = _client.types[defType]();
			a.attributes = {
				'xsi:type': defType
			};
		}
		
		// loop through each field in the type definition and look for fields
		// that were supplied by the user
		_.forEach(def, function(v, k) {
			if (_.has(obj, k)) {
				if (Array.isArray(obj[k])) {
					a[k] = _.map(obj[k], function(o) {
						return getFields(v, o);
					});
				}
				else if (_.isObject(v) && _.isObject(obj[k])) {
					a[k] = getFields(v, obj[k]);
				}
				else {
					a[k] = obj[k];
				}
			}
		});
		
		// return the new arguments object
		return a;
	}
function getFields ( def , obj ) { var a = { } ; // if not an object, return the value if ( ! _ . isObject ( obj ) ) { return obj ; } // check for type override var defType = _ . get ( obj , 'attributes.xsi:type' ) || _ . get ( obj , 'attributes.type' ) ; defType = defType ? defType . replace ( / ^vim25\: / i , '' ) : null ; // if there is a type override and it is a valid type, set the def to that type // and add the type to the attributes if ( defType && _ . has ( _client . types , defType ) ) { def = _client . types [ defType ] ( ) ; a . attributes = { 'xsi:type' : defType } ; } // loop through each field in the type definition and look for fields // that were supplied by the user _ . forEach ( def , function ( v , k ) { if ( _ . has ( obj , k ) ) { if ( Array . isArray ( obj [ k ] ) ) { a [ k ] = _ . map ( obj [ k ] , function ( o ) { return getFields ( v , o ) ; } ) ; } else if ( _ . isObject ( v ) && _ . isObject ( obj [ k ] ) ) { a [ k ] = getFields ( v , obj [ k ] ) ; } else { a [ k ] = obj [ k ] ; } } } ) ; // return the new arguments object return a ; }
recursive function to get the fields in the correct order based on the wsdl definitions
recursive function to get the fields in the correct order based on the wsdl definitions