11# -*- coding: utf-8 -*-
22
33"""
4- firstlanguage
4+ firstlanguage_python
55
66This file was automatically generated by APIMATIC v3.0 (
77 https://www.apimatic.io ).
@@ -142,13 +142,14 @@ def get_schema_path(path):
142142 return path
143143
144144 @staticmethod
145- def serialize_array (key , array , formatting = "indexed" ):
145+ def serialize_array (key , array , formatting = "indexed" , is_query = False ):
146146 """Converts an array parameter to a list of key value tuples.
147147
148148 Args:
149149 key (str): The name of the parameter.
150150 array (list): The value of the parameter.
151151 formatting (str): The type of key formatting expected.
152+ is_query (bool): Decides if the parameters are for query or form.
152153
153154 Returns:
154155 list: A list with key value tuples for the array elements.
@@ -168,6 +169,16 @@ def serialize_array(key, array, formatting="indexed"):
168169 tuples += [("{0}[{1}]" .format (key , index ), element ) for index , element in enumerate (array )]
169170 elif formatting == "plain" :
170171 tuples += [(key , element ) for element in array ]
172+ elif is_query :
173+ if formatting == "csv" :
174+ tuples += [(key , "," .join (str (x ) for x in array ))]
175+
176+ elif formatting == "psv" :
177+ tuples += [(key , "|" .join (str (x ) for x in array ))]
178+
179+ elif formatting == "tsv" :
180+ tuples += [(key , "\t " .join (str (x ) for x in array ))]
181+
171182 else :
172183 raise ValueError ("Invalid format provided." )
173184 else :
@@ -231,41 +242,25 @@ def append_url_with_query_parameters(url,
231242 raise ValueError ("URL is None." )
232243 if parameters is None :
233244 return url
234-
235- for key , value in parameters .items ():
245+ parameters = APIHelper .process_complex_types_parameters (parameters , array_serialization )
246+ for index , value in enumerate (parameters ):
247+ key = value [0 ]
248+ val = value [1 ]
236249 seperator = '&' if '?' in url else '?'
237250 if value is not None :
238- if isinstance (value , list ):
239- value = [element for element in value if element ]
240- if array_serialization == "csv" :
241- url += "{0}{1}={2}" .format (
242- seperator ,
243- key ,
244- "," .join (quote (str (x ), safe = '' ) for x in value )
245- )
246- elif array_serialization == "psv" :
247- url += "{0}{1}={2}" .format (
248- seperator ,
249- key ,
250- "|" .join (quote (str (x ), safe = '' ) for x in value )
251- )
252- elif array_serialization == "tsv" :
253- url += "{0}{1}={2}" .format (
254- seperator ,
255- key ,
256- "\t " .join (quote (str (x ), safe = '' ) for x in value )
257- )
258- else :
259- url += "{0}{1}" .format (
260- seperator ,
261- "&" .join (("{0}={1}" .format (k , quote (str (v ), safe = '' )))
262- for k , v in APIHelper .serialize_array (key , value , array_serialization ))
263- )
264- else :
265- url += "{0}{1}={2}" .format (seperator , key , quote (str (value ), safe = '' ))
251+ url += "{0}{1}={2}" .format (seperator , key , quote (str (val ), safe = '' ))
266252
267253 return url
268254
255+ @staticmethod
256+ def process_complex_types_parameters (query_parameters , array_serialization ):
257+ processed_params = []
258+ for key , value in query_parameters .items ():
259+ processed_params .extend (
260+ APIHelper .form_encode (value , key , array_serialization = array_serialization , is_query = True ))
261+ return processed_params
262+
263+
269264 @staticmethod
270265 def clean_url (url ):
271266 """Validates and processes the given query Url to clean empty slashes.
@@ -315,14 +310,15 @@ def form_encode_parameters(form_parameters,
315310 @staticmethod
316311 def form_encode (obj ,
317312 instance_name ,
318- array_serialization = "indexed" ):
313+ array_serialization = "indexed" , is_query = False ):
319314 """Encodes a model in a form-encoded manner such as person[Name]
320315
321316 Args:
322317 obj (object): The given Object to form encode.
323318 instance_name (string): The base name to appear before each entry
324319 for this object.
325320 array_serialization (string): The format of array parameter serialization.
321+ is_query (bool): Decides if the parameters are for query or form.
326322
327323 Returns:
328324 dict: A dictionary of form encoded properties of the model.
@@ -336,11 +332,11 @@ def form_encode(obj,
336332 if obj is None :
337333 return []
338334 elif isinstance (obj , list ):
339- for element in APIHelper .serialize_array (instance_name , obj , array_serialization ):
340- retval += APIHelper .form_encode (element [1 ], element [0 ], array_serialization )
335+ for element in APIHelper .serialize_array (instance_name , obj , array_serialization , is_query ):
336+ retval += APIHelper .form_encode (element [1 ], element [0 ], array_serialization , is_query )
341337 elif isinstance (obj , dict ):
342338 for item in obj :
343- retval += APIHelper .form_encode (obj [item ], instance_name + "[" + item + "]" , array_serialization )
339+ retval += APIHelper .form_encode (obj [item ], instance_name + "[" + item + "]" , array_serialization , is_query )
344340 else :
345341 retval .append ((instance_name , obj ))
346342
0 commit comments