1
1
import asyncio
2
2
import functools
3
3
import inspect
4
+ import json
4
5
import re
5
6
from inspect import signature
6
7
@@ -46,7 +47,7 @@ def __call__(self, f):
46
47
async def nested_func (** kwargs ):
47
48
# Step 1 - Get expected input details as dict
48
49
expected_inputs = signature (f ).parameters
49
-
50
+
50
51
# Step 2 - Validate JSON inputs
51
52
json_input = None
52
53
if request .headers .get ("Content-Type" ) is not None :
@@ -61,7 +62,8 @@ async def nested_func(**kwargs):
61
62
# Step 3 - Extract list of parameters expected to be lists (otherwise all values are converted to lists)
62
63
expected_list_params = []
63
64
for name , param in expected_inputs .items ():
64
- if str (param .annotation ).startswith ("typing.List" ) or str (param .annotation ).startswith ("typing.Optional[typing.List" ):
65
+ if str (param .annotation ).startswith ("typing.List" ) or str (param .annotation ).startswith (
66
+ "typing.Optional[typing.List" ):
65
67
expected_list_params .append (param .default .alias or name )
66
68
67
69
# Step 4 - Convert request inputs to dicts
@@ -152,7 +154,7 @@ def validate(self, expected_input, all_request_inputs):
152
154
else :
153
155
# Optionals are Unions with a NoneType, so we should check if None is part of Union __args__ (if exist)
154
156
if (
155
- hasattr (expected_input_type , "__args__" ) and type (None ) in expected_input_type .__args__
157
+ hasattr (expected_input_type , "__args__" ) and type (None ) in expected_input_type .__args__
156
158
):
157
159
return user_input
158
160
else :
@@ -202,6 +204,9 @@ def validate(self, expected_input, all_request_inputs):
202
204
user_inputs [count ] = expected_delivery_type .convert (
203
205
value , expected_input_types
204
206
)
207
+ for t in expected_input_types :
208
+ print (f"Expected type: { t } " )
209
+ print (f"Appended value of type { type (user_inputs [count ])} to user_inputs" )
205
210
except ValueError as e :
206
211
raise ValidationError (str (e ), expected_name , expected_input_type )
207
212
@@ -215,6 +220,8 @@ def validate(self, expected_input, all_request_inputs):
215
220
if type (user_input ) is not list :
216
221
validation_success = False
217
222
223
+ print (f"Validation Success? { validation_success } " )
224
+
218
225
# Error if types don't match
219
226
if not validation_success :
220
227
if hasattr (
@@ -229,11 +236,19 @@ def validate(self, expected_input, all_request_inputs):
229
236
original_expected_input_type ,
230
237
)
231
238
232
- # Validate parameter-specific requirements are met
233
- try :
234
- expected_delivery_type .validate (user_input )
235
- except ValueError as e :
236
- raise ValidationError (str (e ), expected_name , expected_input_type )
239
+ print (json .dumps (user_input ))
240
+
241
+ if expected_input_type_str .startswith ("typing.List" ):
242
+ # Validate parameter-specific requirements are met
243
+ try :
244
+ expected_delivery_type .validate (user_input )
245
+ except ValueError as e :
246
+ raise ValidationError (str (e ), expected_name , expected_input_type )
247
+ else :
248
+ try :
249
+ expected_delivery_type .validate (user_inputs [0 ])
250
+ except ValueError as e :
251
+ raise ValidationError (str (e ), expected_name , expected_input_type )
237
252
238
253
# Return input back to parent function
239
254
if expected_input_type_str .startswith ("typing.List" ):
0 commit comments