Skip to content

Instantly share code, notes, and snippets.

@homestar9
Created November 10, 2022 21:34
Show Gist options
  • Save homestar9/1d69b183e4c7e0658067c5b23995aa13 to your computer and use it in GitHub Desktop.
Save homestar9/1d69b183e4c7e0658067c5b23995aa13 to your computer and use it in GitHub Desktop.
/**
* Extends schema definitions based on the passed array of schema objects
* Note: Ignores CFML objects (non-structs) because sometimes the parser gets passed in here for some reason
*
* @objects
*/
function extendObject( array objects ) {
var output = {
"type": "object"
};
objects.each( function( item, index ) {
if ( isStruct( item ) ) {
// If item is an instance of Parser, we need to normalize so we get a CFML struct
if ( isInstanceOf( item, "Parser" ) ) {
item = item.getNormalizedDocument();
}
item.each( function( key, value ) {
if (
output.keyExists( key ) &&
isStruct( output[ key ] )
) {
output[ key ].append( value, true );
} else {
output[ key ] = value
}
} );
}
} );
return output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment