MCPcopy Create free account
hub / github.com/ElementsProject/lightning / search_key_in_conditional_array

Function search_key_in_conditional_array

tools/fromschema.py:51–71  ·  view source on GitHub ↗

search param in all conditional subarrays/objects and return the condition and found array/obj

(request, param)

Source from the content-addressed store, hash-verified

49
50
51def search_key_in_conditional_array(request, param):
52 """search param in all conditional subarrays/objects and return the condition and found array/obj"""
53 one_of_many_array = request.get('oneOfMany', [])
54 paired_with_array = request.get('pairedWith', [])
55
56 # Check if the same parameter is in both 'pairedWith' and 'oneOfMany' and throw an error if found
57 common_key = next((element_one for subarray_one in one_of_many_array for element_one in subarray_one for subarray_paired in paired_with_array if element_one in subarray_paired), '')
58 assert common_key == '', f'The same parameter "{common_key}" cannot be in both "pairedWith" and "oneOfMany"'
59
60 # Search for the parameter in 'oneOfMany' array
61 for sub_array_one in one_of_many_array:
62 if param in sub_array_one:
63 return 'oneOfMany', sub_array_one
64
65 # Search for the parameter in 'pairedWith' array
66 for sub_array_paired in paired_with_array:
67 if param in sub_array_paired:
68 return 'pairedWith', sub_array_paired
69
70 # If param doesn't exist in any of the conditional arrays, return empty condition and None
71 return '', None
72
73
74def output_conditional_params(conditional_sub_array, condition):

Callers 1

generate_headerFunction · 0.85

Calls 2

nextFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected