@@ -932,7 +932,8 @@ def analyze_param(
932
932
ModelField | None
933
933
The type annotation and the Pydantic field representing the parameter
934
934
"""
935
- field_info , type_annotation = get_field_info_and_type_annotation (annotation , value , is_path_param )
935
+ field_info , type_annotation = \
936
+ get_field_info_and_type_annotation (annotation , value , is_path_param , is_response_param )
936
937
937
938
# If the value is a FieldInfo, we use it as the FieldInfo for the parameter
938
939
if isinstance (value , FieldInfo ):
@@ -962,7 +963,9 @@ def analyze_param(
962
963
return field
963
964
964
965
965
- def get_field_info_and_type_annotation (annotation , value , is_path_param : bool ) -> tuple [FieldInfo | None , Any ]:
966
+ def get_field_info_and_type_annotation (
967
+ annotation , value , is_path_param : bool , is_response_param : bool
968
+ ) -> tuple [FieldInfo | None , Any ]:
966
969
"""
967
970
Get the FieldInfo and type annotation from an annotation and value.
968
971
"""
@@ -976,19 +979,33 @@ def get_field_info_and_type_annotation(annotation, value, is_path_param: bool) -
976
979
# If the annotation is a Response type, we recursively call this function with the inner type
977
980
elif get_origin (annotation ) is Response :
978
981
field_info , type_annotation = get_field_info_response_type (annotation , value )
982
+ # If the response param is a tuple with two elements, we use the first element as the type annotation,
983
+ # just like we did in the APIGateway._to_response
984
+ elif is_response_param and get_origin (annotation ) is tuple and len (get_args (annotation )) == 2 :
985
+ field_info , type_annotation = get_field_info_tuple_type (annotation , value )
979
986
# If the annotation is not an Annotated type, we use it as the type annotation
980
987
else :
981
988
type_annotation = annotation
982
989
983
990
return field_info , type_annotation
984
991
985
992
993
+ def get_field_info_tuple_type (annotation , value ) -> tuple [FieldInfo | None , Any ]:
994
+ (inner_type , _ ) = get_args (annotation )
995
+
996
+ # If the inner type is an Annotated type, we need to extract the type annotation and the FieldInfo
997
+ if get_origin (inner_type ) is Annotated :
998
+ return get_field_info_annotated_type (inner_type , value , False )
999
+
1000
+ return None , inner_type
1001
+
1002
+
986
1003
def get_field_info_response_type (annotation , value ) -> tuple [FieldInfo | None , Any ]:
987
1004
# Example: get_args(Response[inner_type]) == (inner_type,) # noqa: ERA001
988
1005
(inner_type ,) = get_args (annotation )
989
1006
990
1007
# Recursively resolve the inner type
991
- return get_field_info_and_type_annotation (inner_type , value , False )
1008
+ return get_field_info_and_type_annotation (inner_type , value , False , True )
992
1009
993
1010
994
1011
def get_field_info_annotated_type (annotation , value , is_path_param : bool ) -> tuple [FieldInfo | None , Any ]:
0 commit comments