src/swagger2x.py
def find_key_link(rec_dict, target, depth=0):
    """
    find the first key recursively
    also traverse lists (arrays, oneOf,..) but only returns the first occurance
    :param rec_dict: dict to search in, json schema dict, so it is combination of dict and arrays
    :param target: target key to search for
    :param depth: depth of the search (recursion)
    :return:
    """
    if isinstance(rec_dict, dict):
        # direct key
        for key, value in rec_dict.items():
            if key == target:
                return rec_dict[key]
        # key is in array
        rvalues = []
        found = False
        for key, value in rec_dict.items():
            if key in ["oneOf", "allOf", "anyOf"]:
                for val in value:
                    if val == target:
                        return val
                    if isinstance(val, dict):
                        r = find_key_link(val, target, depth + 1)
                        if r is not None:
                            found = True
                            # TODO: this should return an array, now it only returns the last found item
                            rvalues = r
        if found:
            return rvalues
        # key is an dict
        for key, value in rec_dict.items():
            r = find_key_link(value, target, depth + 1)
            if r is not None:
                return r

    find the first key recursively
    also traverse lists (arrays, oneOf,..) but only returns the first occurance
    :param rec_dict: dict to search in, json schema dict, so it is combination of dict and arrays
    :param target: target key to search for
    :param depth: depth of the search (recursion)
    :return:
    
find the first key recursively
also traverse lists (arrays, oneOf,..) but only returns the first occurance
find the first key recursively also traverse lists ( arrays oneOf .. ) but only returns the first occurance
def find_key_link(rec_dict, target, depth=0):
    if isinstance(rec_dict, dict):
        for key, value in rec_dict.items():
            if key == target:
                return rec_dict[key]
        rvalues = []
        found = False
        for key, value in rec_dict.items():
            if key in ["oneOf", "allOf", "anyOf"]:
                for val in value:
                    if val == target:
                        return val
                    if isinstance(val, dict):
                        r = find_key_link(val, target, depth + 1)
                        if r is not None:
                            found = True
                            rvalues = r
        if found:
            return rvalues
        for key, value in rec_dict.items():
            r = find_key_link(value, target, depth + 1)
            if r is not None:
                return r
def find_key_link ( rec_dict , target , depth = 0 ) : if isinstance ( rec_dict , dict ) : for key , value in rec_dict . items ( ) : if key == target : return rec_dict [ key ] rvalues = [ ] found = False for key , value in rec_dict . items ( ) : if key in [ "oneOf" , "allOf" , "anyOf" ] : for val in value : if val == target : return val if isinstance ( val , dict ) : r = find_key_link ( val , target , depth + 1 ) if r is not None : found = True rvalues = r if found : return rvalues for key , value in rec_dict . items ( ) : r = find_key_link ( value , target , depth + 1 ) if r is not None : return r
find the first key recursively
also traverse lists (arrays, oneOf,..) but only returns the first occurance
find the first key recursively also traverse lists ( arrays oneOf .. ) but only returns the first occurance
"""
    find the first key recursively
    also traverse lists (arrays, oneOf,..) but only returns the first occurance
    :param rec_dict: dict to search in, json schema dict, so it is combination of dict and arrays
    :param target: target key to search for
    :param depth: depth of the search (recursion)
    :return:
    """ # direct key
 # key is in array
 # TODO: this should return an array, now it only returns the last found item
 # key is an dict

None
rec_dict
dict to search in, json schema dict, so it is combination of dict and arrays
dict to search in json schema dict so it is combination of dict and arrays
target
target key to search for
target key to search for
depth
depth of the search (recursion)
depth of the search ( recursion )