@@ -171,24 +171,38 @@ def generate_rest_func_params(
171
171
else :
172
172
if field_obj := dataclass_fields .get (param_name ):
173
173
# Check Annotated metadata
174
- if annotated_type := param_type_util .get_annotated_type (field_obj .type ):
175
- if isinstance (annotated_type , list | tuple ):
176
- # Select the first annotaed type where the type of the given param value matches
177
- annotated_type = [
178
- x
179
- for x in annotated_type
180
- if param_type_util .is_type_of (get_args (annotated_type )[0 ], type (param_value ))
181
- ] or annotated_type [0 ]
182
-
183
- # Process alias name and query parameter
184
- metadata = annotated_type .__metadata__
185
- if alias_param := [x for x in metadata if isinstance (x , Alias )]:
186
- assert len (alias_param ) == 1
187
- # Resolve the actual param name
188
- param_name = alias_param [0 ].value
189
-
190
- if "query" in metadata :
191
- query [param_name ] = param_value
174
+ if field_obj := dataclass_fields .get (param_name ):
175
+ # Check Annotated metadata
176
+ if annotated_type := param_type_util .get_annotated_type (field_obj .type ):
177
+ if isinstance (annotated_type , list | tuple ):
178
+ # This field has more than one Annotated[] as a union. We will try to find the right one for
179
+ # this request where the type of the given param value matches. If none of them match,
180
+ # select the first one and log warning message
181
+ try :
182
+ annotated_type = next (
183
+ x
184
+ for x in annotated_type
185
+ if param_type_util .is_type_of (get_args (x )[0 ], type (param_value ))
186
+ )
187
+ except StopIteration :
188
+ annotated_type = annotated_type [0 ]
189
+ logger .warning (
190
+ f"The field type of '{ endpoint .model .__name__ } .{ param_name } ' has more than 1 "
191
+ f"Annotated[] types, but the type of the provided value does not match with any of "
192
+ f"them. The first annotated type will be used for this API call.\n "
193
+ f"- Defined field type: { field_obj .type } \n "
194
+ f"- Provided value type: { type (param_value )} "
195
+ )
196
+
197
+ # Process alias name and query parameter
198
+ metadata = annotated_type .__metadata__
199
+ if alias_param := [x for x in metadata if isinstance (x , Alias )]:
200
+ assert len (alias_param ) == 1
201
+ # Resolve the actual param name
202
+ param_name = alias_param [0 ].value
203
+
204
+ if "query" in metadata :
205
+ query [param_name ] = param_value
192
206
193
207
if param_name not in query .keys ():
194
208
if use_query_string :
0 commit comments