def resolve_references(config, definitions):
 for (key, value) in config.items():
  if isinstance(value, dict):
   if ((len(value) == 1) and (list(value.keys())[0] == '$ref')):
    config[key] = definitions[list(value.values())[0]]
   else:
    resolve_references(value, definitions)

def resolve_references ( config , definitions ) : for ( key , value ) in config . items ( ) : if isinstance ( value , dict ) : if ( ( len ( value ) == 1 ) and ( list ( value . keys ( ) ) [ 0 ] == '$ref' ) ) : config [ key ] = definitions [ list ( value . values ( ) ) [ 0 ] ] else : resolve_references ( value , definitions )
recursively replace $ref keys .